serde-diff icon indicating copy to clipboard operation
serde-diff copied to clipboard

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

Open kabergstrom opened this issue 5 years ago • 5 comments

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 avatar Jan 25 '20 20:01 kabergstrom

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

Boscop avatar Jan 28 '20 10:01 Boscop

I implemented that here: https://github.com/amethyst/serde-diff/commit/5afe403d0d4fb80f5d072f4836f1a72bf6da6dff

kabergstrom avatar Jan 28 '20 10:01 kabergstrom

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

Boscop avatar Jan 28 '20 10:01 Boscop

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

kabergstrom avatar Jan 28 '20 10:01 kabergstrom

Above comment has become:

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

TimonPost avatar Feb 07 '20 16:02 TimonPost