perf(serialize): faster serialization of objects and classes#141
Merged
perf(serialize): faster serialization of objects and classes#141
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #141 +/- ##
===========================================
+ Coverage 80.31% 95.84% +15.52%
===========================================
Files 8 8
Lines 1006 481 -525
Branches 111 126 +15
===========================================
- Hits 808 461 -347
+ Misses 198 18 -180
- Partials 0 2 +2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as outdated.
Set
This reverts commit fe7b466.
Set
Collaborator
Author
✓ test/benchmarks.bench.ts > benchmarks > serialize - presets > count:256, size:small 1216ms
name hz min max mean p75 p99 p995 p999 rme samples
· ohash @ main 7,859.08 0.1117 0.5755 0.1272 0.1195 0.3489 0.3879 0.4571 ±0.99% 3930
· ohash @ dev 11,888.49 0.0735 0.5062 0.0841 0.0786 0.2925 0.3252 0.3708 ±1.05% 5945 fastest
BENCH Summary
ohash @ dev - test/benchmarks.bench.ts > benchmarks > serialize - presets > count:256, size:small
1.51x faster than ohash @ mainclk: ~5.25 GHz
cpu: AMD Ryzen 9 7950X 16-Core Processor
runtime: bun 1.2.4 (x64-linux)
benchmark avg (min … max) p75 / p99 (min … top 1%)
------------------------------------------- -------------------------------
• count:256, size:small
------------------------------------------- -------------------------------
ohash @ main 116.81 µs/iter 117.85 µs █
(100.96 µs … 1.93 ms) 193.60 µs █
( 0.00 b … 528.00 kb) 16.70 kb ██▃▄▆▄▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁
ohash @ dev 78.58 µs/iter 75.25 µs █
(63.59 µs … 1.84 ms) 142.25 µs █
( 0.00 b … 792.00 kb) 20.71 kb ▂█▆▂▃▄▂▁▁▁▁▁▁▁▁▂▂▁▁▁▁
summary
ohash @ dev
1.49x faster than ohash @ main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Since we know
Object.entries(object)returnsArray<[string, any]>we can use a faster path to:compare()because we can callString.localeCompare()directly on keysserialize()for keys because they can be only stringsI created a new function for handling theIterablebut we can also merge it to the existingserializeObjectEntries()with a flag likeonlyStringKeysand add conditions to handle that.The performance gains are not significant though.- Used a faster path later.