Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally use perfect hashing for field path matching in derive macro apply #7

Open
kabergstrom opened this issue Jan 25, 2020 · 5 comments
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed

Comments

@kabergstrom
Copy link
Collaborator

Field paths are serialized as strings, and applying a diff to a large struct can be costly due to excessive string matching. It should be possible to leverage one of the crates in the ecosystem for perfect hashing when generating code for apply in the derive macro.

@kabergstrom kabergstrom added enhancement New feature or request help wanted Extra attention is needed good first issue Good for newcomers labels Jan 25, 2020
@Boscop
Copy link
Contributor

Boscop commented Jan 28, 2020

@kabergstrom What about using field indices instead of field names, like with tuples?
This would reduce the size & cpu usage the most.

@kabergstrom
Copy link
Collaborator Author

I implemented that here: 5afe403

@Boscop
Copy link
Contributor

Boscop commented Jan 28, 2020

Ah, nice! And how to enable that for a struct?

@kabergstrom
Copy link
Collaborator Author

kabergstrom commented Jan 28, 2020

Use Diff::serializable_with_mode(old, new, FieldPathMode::Index) instead of Diff::serializable. I don't like this API though, I want to it to be more like a Config struct so that adding/removing options doesn't break people's code. Just haven't gotten to it yet

@TimonPost
Copy link
Member

Above comment has become:

    let diff = Config::new()
        .with_field_path_mode(FieldPathMode::Index)
        .serializable_diff(&old, &new);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants