serde icon indicating copy to clipboard operation
serde copied to clipboard

Performance Optimization in `serde_derive` Macro

Open nurmohammed840 opened this issue 1 year ago • 2 comments

Context

The quote2 crate, which is an alternative lightweight version of quote, offers some improvements over quote

Proposal

If requested, I would be happy to submit a pull request to implement these optimizations. My proposal involves refactoring existing code to leverage the improved design in quote2

Please let me know if this contribution would be valuable. I can provide more details or send a pull request directly for review.

nurmohammed840 avatar Oct 03 '24 06:10 nurmohammed840

We don't have the capacity for reviewing an entire crate for feasability.

If you want to make a case, I recommend:

  1. creating benchmarks, ideally by swapping out the quote usage in serde and showing concrete numbers
  2. Running crater-at-home to see if swapping it out will break any crates (this requires extending crater-at-home to allow injecting patched crates)
  3. Writing a paragraph or two explaining the differences between the crates

All of these are significant effort and may not pan out, so only do this if you think there is a strong argument for switching and want to convince us.

oli-obk avatar Oct 03 '24 12:10 oli-obk

So, At the moment I only refactor serialization part, And the result is very promising 👌

Here’s a link to the prototype implementation

System Info

  • CPU: Ryzen 7 5700 (3.8GHz - 4.6GHz)

Benchmark Result

Iteration File serde_derive serde_derive_next Improvement Faster
1 simple.rs 253.5µs 120µs 52.66% 2.11x
user.rs 339.9µs 210.9µs 37.96% 1.61x
10 simple.rs 536µs 331.8µs 38.06% 1.61x
user.rs 2.8184ms 1.6602ms 41.09% 1.70x
100 simple.rs 4.6072ms 2.8672ms 37.77% 1.61x
user.rs 27.6456ms 15.1838ms 45.08% 1.82x
10,000 simple.rs 447.8222ms 282.0575ms 37.03% 1.59x
user.rs 2.3379857s 1.3935152s 40.43% 1.68x

@oli-obk, let me know, If I should continue refactoring (deserialization part) rest of the codebase.

nurmohammed840 avatar Oct 04 '24 16:10 nurmohammed840