Skip to content

Make simd-json more Rust idiomatic #478

Description

@Ygg01

This crate isn't very idiomatic. Sure it does something low level but consider following:

  1. stry! macro can be replaced by ? operator. Is there a reason for stry!? Comments mention performances degradation but doing a cargo bench reveals same or +20% performance uplift. See summary below
simd-json without `stry` macro
PS C:\projects\simd-json> cargo bench
   Compiling simd-json v0.18.1 (C:\projects\simd-json)
    Finished `bench` profile [optimized] target(s) in 26.89s                                                                                                       
     Running benches\parse.rs (target\release\deps\parse-4ec45711d4f26869.exe)
Gnuplot not found, using plotters backend
apache_builds/simd_json::to_borrowed_value
                        time:   [175.15 µs 175.66 µs 176.24 µs]
                        thrpt:  [712.62 MiB/s 714.98 MiB/s 717.07 MiB/s]
                 change:
                        time:   [−1.4873% −0.6701% +0.0096%] (p = 0.09 > 0.05)
                        thrpt:  [−0.0096% +0.6746% +1.5098%]
                        No change in performance detected.
Found 5 outliers among 100 measurements (5.00%)
  3 (3.00%) high mild
  2 (2.00%) high severe
apache_builds/simd_json::to_borrowed_value_with_buffers
                        time:   [175.21 µs 175.57 µs 175.98 µs]
                        thrpt:  [713.70 MiB/s 715.35 MiB/s 716.81 MiB/s]
                 change:
                        time:   [+0.7279% +1.2116% +1.6842%] (p = 0.00 < 0.05)
                        thrpt:  [−1.6563% −1.1971% −0.7227%]
                        Change within noise threshold.
Found 8 outliers among 100 measurements (8.00%)
  5 (5.00%) high mild
  3 (3.00%) high severe
apache_builds/simd_json::to_owned_value
                        time:   [273.39 µs 275.07 µs 276.53 µs]
                        thrpt:  [454.17 MiB/s 456.59 MiB/s 459.39 MiB/s]
                 change:
                        time:   [−0.0069% +0.9300% +1.7901%] (p = 0.03 < 0.05)
                        thrpt:  [−1.7586% −0.9214% +0.0069%]
                        Change within noise threshold.

event_stacktrace_10kb/simd_json::to_borrowed_value
                        time:   [3.3200 µs 3.3392 µs 3.3594 µs]
                        thrpt:  [2.7521 GiB/s 2.7687 GiB/s 2.7848 GiB/s]
                 change:
                        time:   [−10.636% −6.7627% −3.3357%] (p = 0.00 < 0.05)
                        thrpt:  [+3.4508% +7.2532% +11.902%]
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe
event_stacktrace_10kb/simd_json::to_borrowed_value_with_buffers
                        time:   [2.9360 µs 2.9481 µs 2.9604 µs]
                        thrpt:  [3.1230 GiB/s 3.1360 GiB/s 3.1489 GiB/s]
                 change:
                        time:   [−24.095% −17.963% −12.200%] (p = 0.00 < 0.05)
                        thrpt:  [+13.895% +21.896% +31.744%]
                        Performance has improved.
Found 16 outliers among 100 measurements (16.00%)
  14 (14.00%) low mild
  1 (1.00%) high mild
  1 (1.00%) high severe
event_stacktrace_10kb/simd_json::to_owned_value
                        time:   [5.0036 µs 5.0383 µs 5.0736 µs]
                        thrpt:  [1.8222 GiB/s 1.8350 GiB/s 1.8477 GiB/s]
                 change:
                        time:   [−18.813% −13.410% −8.3508%] (p = 0.00 < 0.05)
                        thrpt:  [+9.1117% +15.487% +23.172%]
                        Performance has improved.

github_events/simd_json::to_borrowed_value
                        time:   [67.730 µs 67.953 µs 68.169 µs]
                        thrpt:  [930.63 MiB/s 933.59 MiB/s 936.66 MiB/s]
                 change:
                        time:   [−30.311% −22.011% −14.111%] (p = 0.00 < 0.05)
                        thrpt:  [+16.429% +28.223% +43.494%]
                        Performance has improved.
github_events/simd_json::to_borrowed_value_with_buffers
                        time:   [65.195 µs 65.798 µs 66.820 µs]
                        thrpt:  [949.42 MiB/s 964.16 MiB/s 973.08 MiB/s]
                 change:
                        time:   [−20.752% −15.558% −10.505%] (p = 0.00 < 0.05)
                        thrpt:  [+11.738% +18.424% +26.186%]
                        Performance has improved.
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) high mild
  2 (2.00%) high severe
github_events/simd_json::to_owned_value
                        time:   [119.14 µs 120.18 µs 121.10 µs]
                        thrpt:  [523.85 MiB/s 527.90 MiB/s 532.49 MiB/s]
                 change:
                        time:   [−23.570% −17.778% −11.969%] (p = 0.00 < 0.05)
                        thrpt:  [+13.596% +21.623% +30.839%]
                        Performance has improved.

canada/simd_json::to_borrowed_value
                        time:   [8.9994 ms 9.1612 ms 9.3312 ms]
                        thrpt:  [230.06 MiB/s 234.33 MiB/s 238.55 MiB/s]
                 change:
                        time:   [−25.894% −19.910% −13.630%] (p = 0.00 < 0.05)
                        thrpt:  [+15.781% +24.859% +34.942%]
                        Performance has improved.
canada/simd_json::to_borrowed_value_with_buffers
                        time:   [8.2364 ms 8.3711 ms 8.5190 ms]
                        thrpt:  [252.00 MiB/s 256.45 MiB/s 260.65 MiB/s]
                 change:
                        time:   [−28.915% −23.370% −17.490%] (p = 0.00 < 0.05)
                        thrpt:  [+21.198% +30.497% +40.677%]
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe
canada/simd_json::to_owned_value
                        time:   [7.1303 ms 7.2486 ms 7.3748 ms]
                        thrpt:  [291.10 MiB/s 296.17 MiB/s 301.08 MiB/s]
                 change:
                        time:   [−10.879% −4.5599% +0.1846%] (p = 0.14 > 0.05)
                        thrpt:  [−0.1842% +4.7778% +12.207%]
                        No change in performance detected.
Found 5 outliers among 100 measurements (5.00%)
  5 (5.00%) high mild
#

citm_catalog/simd_json::to_borrowed_value
                        time:   [3.0979 ms 3.1469 ms 3.1964 ms]
                        thrpt:  [530.39 MiB/s 538.72 MiB/s 547.25 MiB/s]
                 change:
                        time:   [−0.5444% +1.9231% +4.4387%] (p = 0.13 > 0.05)
                        thrpt:  [−4.2500% −1.8868% +0.5474%]
                        No change in performance detected.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
citm_catalog/simd_json::to_borrowed_value_with_buffers
                        time:   [2.7820 ms 2.8159 ms 2.8507 ms]
                        thrpt:  [594.71 MiB/s 602.05 MiB/s 609.38 MiB/s]
                 change:
                        time:   [−1.6340% +1.2378% +4.3310%] (p = 0.44 > 0.05)
                        thrpt:  [−4.1512% −1.2227% +1.6611%]
                        No change in performance detected.
Found 4 outliers among 100 measurements (4.00%)
  2 (2.00%) high mild
  2 (2.00%) high severe
Benchmarking citm_catalog/simd_json::to_owned_value: Warming up for 1.0000 s
Warning: Unable to complete 100 samples in 20.0s. You may wish to increase target time to 24.6s, enable flat sampling, or reduce sample count to 60.
citm_catalog/simd_json::to_owned_value
                        time:   [3.2175 ms 3.2804 ms 3.3457 ms]
                        thrpt:  [506.71 MiB/s 516.81 MiB/s 526.91 MiB/s]
                 change:
                        time:   [−3.6698% −0.9384% +1.8610%] (p = 0.52 > 0.05)
                        thrpt:  [−1.8270% +0.9473% +3.8096%]
                        No change in performance detected.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild

log/simd_json::to_borrowed_value
                        time:   [2.3223 µs 2.3351 µs 2.3499 µs]
                        thrpt:  [883.10 MiB/s 888.68 MiB/s 893.61 MiB/s]
                 change:
                        time:   [−6.3810% −4.2839% −2.5244%] (p = 0.00 < 0.05)
                        thrpt:  [+2.5898% +4.4756% +6.8159%]
                        Performance has improved.
Found 1 outliers among 100 measurements (1.00%)
  1 (1.00%) high mild
log/simd_json::to_borrowed_value_with_buffers
                        time:   [1.9943 µs 2.0026 µs 2.0107 µs]
                        thrpt:  [1.0079 GiB/s 1.0119 GiB/s 1.0162 GiB/s]
                 change:
                        time:   [−14.538% −11.649% −9.5161%] (p = 0.00 < 0.05)
                        thrpt:  [+10.517% +13.185% +17.011%]
                        Performance has improved.
Found 3 outliers among 100 measurements (3.00%)
  2 (2.00%) high mild
  1 (1.00%) high severe
log/simd_json::to_owned_value
                        time:   [5.2520 µs 5.3025 µs 5.3446 µs]
                        thrpt:  [388.28 MiB/s 391.36 MiB/s 395.12 MiB/s]
                 change:
                        time:   [−6.0024% −3.6255% −1.3327%] (p = 0.00 < 0.05)
                        thrpt:  [+1.3507% +3.7619% +6.3857%]
                        Performance has improved.

twitter/simd_json::to_borrowed_value
                        time:   [876.71 µs 890.32 µs 903.97 µs]
                        thrpt:  [682.57 MiB/s 693.04 MiB/s 703.79 MiB/s]
                 change:
                        time:   [−4.0587% −1.7328% +0.6089%] (p = 0.15 > 0.05)
                        thrpt:  [−0.6052% +1.7634% +4.2304%]
                        No change in performance detected.
Found 3 outliers among 100 measurements (3.00%)
  3 (3.00%) high mild
twitter/simd_json::to_borrowed_value_with_buffers
                        time:   [843.01 µs 852.99 µs 863.41 µs]
                        thrpt:  [714.63 MiB/s 723.36 MiB/s 731.93 MiB/s]
                 change:
                        time:   [−4.3779% −2.0909% +0.1324%] (p = 0.07 > 0.05)
                        thrpt:  [−0.1322% +2.1356% +4.5784%]
                        No change in performance detected.
Found 4 outliers among 100 measurements (4.00%)
  1 (1.00%) high mild
  3 (3.00%) high severe
twitter/simd_json::to_owned_value
                        time:   [1.3433 ms 1.3616 ms 1.3808 ms]
                        thrpt:  [446.87 MiB/s 453.17 MiB/s 459.34 MiB/s]
                 change:
                        time:   [−5.0699% −2.4445% +0.0528%] (p = 0.08 > 0.05)
                        thrpt:  [−0.0528% +2.5057% +5.3407%]
                        No change in performance detected.
Found 15 outliers among 100 measurements (15.00%)
  11 (11.00%) low mild
  4 (4.00%) high mild

     Running benches\to_tape.rs (target\release\deps\to_tape-3df585aa6d605f5c.exe)
Gnuplot not found, using plotters backend
WARNING: skipping benchmark 'apache_builds': feature `bench-apache_builds` not enabled (use `--features bench-all`)
WARNING: skipping benchmark 'event_stacktrace_10kb': feature `bench-event_stacktrace_10kb` not enabled (use `--features bench-all`)
WARNING: skipping benchmark 'github_events': feature `bench-github_events` not enabled (use `--features bench-all`)
WARNING: skipping benchmark 'canada': feature `bench-canada` not enabled (use `--features bench-all`)
WARNING: skipping benchmark 'citm_catalog': feature `bench-citm_catalog` not enabled (use `--features bench-all`)
WARNING: skipping benchmark 'log': feature `bench-log` not enabled (use `--features bench-all`)
WARNING: skipping benchmark 'twitter': feature `bench-twitter` not enabled (use `--features bench-all`)
  1. No usage of Shift/Add/BitXor to make code easier to grok.
  2. Using &[u8; 64] would have speed up code from my experience doing an operation on predetermined array of u8 is faster than [u8]`. Often Rust autovectorizes such code. Needs testing in Godbolt.
  3. Lots of usage of fully qualified names (e.g. std::result::Result instead of result), that's not really idiomatic, but maybe sometimes it makes sense if there are two same name struct in namespace.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions