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

perf(serialize): optimized sorting for small objects and arrays #151

Open
wants to merge 14 commits into
base: perf/faster-compare
Choose a base branch
from

Conversation

zsilbi
Copy link
Collaborator

@zsilbi zsilbi commented Mar 9, 2025

For smaller object keys and Setvalues with less than ~10 elements (which is quite common) we can use a simple insertion sort.
Otherwise we fall back to the native sort().

Compared to target: #144

  test/benchmarks.bench.ts > benchmarks > serialize - presets > count:1, size:small 2190ms
     name                       hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · ohash @ d7f7f9d  2,734,883.45  0.0003  3.0094  0.0004  0.0003  0.0007  0.0008  0.0090  ±1.55%  1367442
   · ohash @ dev      4,263,019.50  0.0002  0.2779  0.0002  0.0002  0.0004  0.0005  0.0006  ±0.21%  2131510   fastest

  test/benchmarks.bench.ts > benchmarks > serialize - presets > count:256, size:small 1210ms
     name                    hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · ohash @ d7f7f9d  13,446.55  0.0647  0.4242  0.0744  0.0702  0.2418  0.2760  0.3444  ±0.89%     6727
   · ohash @ dev      18,352.54  0.0480  0.4818  0.0545  0.0513  0.2242  0.2515  0.3314  ±0.93%     9177   fastest

 BENCH  Summary

  ohash @ dev - test/benchmarks.bench.ts > benchmarks > serialize - presets > count:1, size:small
    1.56x faster than ohash @ d7f7f9d

  ohash @ dev - test/benchmarks.bench.ts > benchmarks > serialize - presets > count:256, size:small
    1.36x faster than ohash @ d7f7f9d
clk: ~5.31 GHz
cpu: AMD Ryzen 9 7950X 16-Core Processor
runtime: bun 1.2.5 (x64-linux)

benchmark                   avg (min … max) p75 / p99    (min … top 1%)
------------------------------------------- -------------------------------
• count:1, size:small
------------------------------------------- -------------------------------
ohash @ d7f7f9d              207.86 ns/iter 199.94 ns █▇
                    (190.37 ns … 560.65 ns) 427.13 ns ██
                    (  0.00  b … 396.00  b)   4.83  b ██▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

ohash @ dev                  170.54 ns/iter 160.53 ns █▇
                    (149.46 ns … 601.63 ns) 415.21 ns ██
                    (  0.00  b … 726.00  b)  11.54  b ██▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

summary
  ohash @ dev
   1.22x faster than ohash @ d7f7f9d

• count:256, size:small
------------------------------------------- -------------------------------
ohash @ d7f7f9d               66.88 µs/iter  59.40 µs  
                       (50.93 µs … 2.02 ms) 141.50 µs  
                    (  0.00  b … 528.00 kb)  13.95 kb ▃█▅▂▃▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁

ohash @ dev                   49.34 µs/iter  49.51 µs         
                      (48.01 µs … 51.76 µs)  50.43 µs      █▅█ ▅▅      
                    (619.00  b …  13.08 kb)   2.48 kb █▁▁█▁▁▁███▁██▁█▁▁▁▁▁█

summary
  ohash @ dev
   1.36x faster than ohash @ d7f7f9d

@zsilbi zsilbi changed the title perf(serialize): optimized sorting for small objects perf(serialize): optimized sorting for small objects and arrays Mar 9, 2025
@zsilbi zsilbi marked this pull request as ready for review March 10, 2025 10:50
@zsilbi zsilbi force-pushed the perf/optimized-sort branch from 74c561b to 552c05b Compare March 11, 2025 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant