Skip to content

perf: use simd optimzed json string escape impl#158

Merged
graphite-app[bot] merged 1 commit intomainfrom
09-23-perf_use_simd_optimzed_json_string_escape_impl
Sep 23, 2025
Merged

perf: use simd optimzed json string escape impl#158
graphite-app[bot] merged 1 commit intomainfrom
09-23-perf_use_simd_optimzed_json_string_escape_impl

Conversation

@Brooooooklyn
Copy link
Member

@Brooooooklyn Brooooooklyn commented Sep 23, 2025

benchmark results on GitHub actions runner: https://docs.rs/json-escape-simd/latest/json_escape_simd/

GitHub Actions x86_64 (ubuntu-latest)

AVX2 enabled.

RxJS payload (~10k iterations)

Implementation Median time vs fastest
escape simd 345.06 µs 1.00×
escape v_jsonescape 576.25 µs 1.67×
escape generic 657.94 µs 1.91×
serde_json 766.72 µs 2.22×
json-escape 782.65 µs 2.27×

Escape AFFiNE sources (~300 iterations)

Implementation Median time vs fastest
escape simd 12.84 ms 1.00×
escape v_jsonescape 19.66 ms 1.53×
escape generic 22.53 ms 1.75×
serde_json 24.65 ms 1.92×
json-escape 26.64 ms 2.07×

Copy link
Member Author

Brooooooklyn commented Sep 23, 2025


How to use the Graphite Merge Queue

Add the label merge to this PR to add it to the merge queue.

You must have a Graphite account in order to use the merge queue. Sign up using this link.

An organization admin has enabled the Graphite Merge Queue in this repository.

Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue.

This stack of pull requests is managed by Graphite. Learn more about stacking.

@codspeed-hq
Copy link

codspeed-hq bot commented Sep 23, 2025

CodSpeed Performance Report

Merging #158 will degrade performances by 7.69%

Comparing 09-23-perf_use_simd_optimzed_json_string_escape_impl (4a76d74) with main (e6aa0cd)

Summary

⚡ 1 improvement
❌ 2 (👁 1) regressions
✅ 2 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
generate_lookup_table 1.3 µs 1.3 µs +4.59%
to_json 5.6 µs 5.6 µs -1.04%
👁 to_json_string 6.3 µs 6.9 µs -7.69%

@Brooooooklyn Brooooooklyn marked this pull request as ready for review September 23, 2025 08:20
@Brooooooklyn Brooooooklyn force-pushed the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch from 2a4368c to 90dff02 Compare September 23, 2025 09:18
@Brooooooklyn
Copy link
Member Author

I can see 2% - 4% performance boost (10 times run) on my Linux WSL in apps/10000 rolldown benchmark with sourceMap: true option

❯ hyperfine -n json-escape-simd "node ../../../rolldown/packages/rolldown/dist/cli.mjs build --config rolldown.config.mjs" -n main "node ../../node_
modules/rolldown/dist/cli.mjs build --config rolldown.config.mjs"
Benchmark 1: json-escape-simd
  Time (mean ± σ):      1.527 s ±  0.096 s    [User: 2.914 s, System: 1.349 s]
  Range (min … max):    1.427 s …  1.681 s    10 runs
 
Benchmark 2: main
  Time (mean ± σ):      1.585 s ±  0.098 s    [User: 2.903 s, System: 1.523 s]
  Range (min … max):    1.438 s …  1.707 s    10 runs
 
Summary
  'json-escape-simd' ran
    1.04 ± 0.09 times faster than 'main'

@Brooooooklyn Brooooooklyn force-pushed the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch from 90dff02 to 247341d Compare September 23, 2025 09:50
@Boshen
Copy link
Member

Boshen commented Sep 23, 2025

CodSpeed Performance Report

Merging #158 will degrade performances by 10.35%

Comparing 09-23-perf_use_simd_optimzed_json_string_escape_impl (247341d) with main (71b57ff)

Summary

❌ 3 regressions ✅ 2 untouched

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark BASE HEAD Change
generate_lookup_table 1.5 µs 1.6 µs -7.17%
to_json 6.2 µs 6.3 µs -1.84%
to_json_string 7.1 µs 7.9 µs -10.35%

There's probably an allocation somewhere?

@Brooooooklyn Brooooooklyn force-pushed the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch from 247341d to 04003cd Compare September 23, 2025 11:11
@Brooooooklyn
Copy link
Member Author

There's probably an allocation somewhere?

You are absolutely right!

@Brooooooklyn Brooooooklyn force-pushed the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch from 04003cd to 54e2a99 Compare September 23, 2025 12:01
@Brooooooklyn Brooooooklyn changed the base branch from main to graphite-base/158 September 23, 2025 13:04
@Brooooooklyn Brooooooklyn force-pushed the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch from 54e2a99 to 5034b21 Compare September 23, 2025 13:04
@Brooooooklyn Brooooooklyn changed the base branch from graphite-base/158 to 09-23-build_enable_fat_lto_in_bench_profile September 23, 2025 13:04
@graphite-app graphite-app bot changed the base branch from 09-23-build_enable_fat_lto_in_bench_profile to graphite-base/158 September 23, 2025 13:44
@graphite-app graphite-app bot force-pushed the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch from ea7500d to 8ab2f7b Compare September 23, 2025 13:46
@graphite-app graphite-app bot changed the base branch from graphite-base/158 to main September 23, 2025 13:47
@graphite-app graphite-app bot force-pushed the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch from 8ab2f7b to dde55a1 Compare September 23, 2025 13:47
@Brooooooklyn Brooooooklyn force-pushed the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch from dde55a1 to f7848a6 Compare September 23, 2025 14:04
@Boshen Boshen added the merge label Sep 23, 2025
Copy link
Member

Boshen commented Sep 23, 2025

Merge activity

benchmark results on GitHub actions runner: https://docs.rs/json-escape-simd/latest/json_escape_simd/

### GitHub Actions x86_64 (`ubuntu-latest`)

`AVX2` enabled.

**RxJS payload (~10k iterations)**

| Implementation        | Median time   | vs fastest |
| --------------------- | ------------- | ---------- |
| **`escape simd`**     | **345.06 µs** | **1.00×**  |
| `escape v_jsonescape` | 576.25 µs     | 1.67×      |
| `escape generic`      | 657.94 µs     | 1.91×      |
| `serde_json`          | 766.72 µs     | 2.22×      |
| `json-escape`         | 782.65 µs     | 2.27×      |

**Escape AFFiNE sources  (~300 iterations)**

| Implementation        | Median time  | vs fastest |
| --------------------- | ------------ | ---------- |
| **`escape simd`**     | **12.84 ms** | **1.00×**  |
| `escape v_jsonescape` | 19.66 ms     | 1.53×      |
| `escape generic`      | 22.53 ms     | 1.75×      |
| `serde_json`          | 24.65 ms     | 1.92×      |
| `json-escape`         | 26.64 ms     | 2.07×      |
@graphite-app graphite-app bot force-pushed the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch from 06a925c to 4a76d74 Compare September 23, 2025 14:43
@graphite-app graphite-app bot merged commit 4a76d74 into main Sep 23, 2025
8 checks passed
@graphite-app graphite-app bot deleted the 09-23-perf_use_simd_optimzed_json_string_escape_impl branch September 23, 2025 14:45
@graphite-app graphite-app bot removed the merge label Sep 23, 2025
@Boshen Boshen mentioned this pull request Sep 23, 2025
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.

2 participants