Skip to content

improve text encoder encode performance#5448

Open
anonrig wants to merge 30 commits intomainfrom
yagiz/experiment-value-view
Open

improve text encoder encode performance#5448
anonrig wants to merge 30 commits intomainfrom
yagiz/experiment-value-view

Conversation

@anonrig
Copy link
Member

@anonrig anonrig commented Oct 31, 2025

Improves Next.js benchmarks by 4-7% and WebAssembly applications by 5%

Important disclaimer: Codspeed will not show any improvement (although you can look into previous edits of the codspeed post) because this change is behind an autogate.


Sharing @mhart's benchmark results:

Before:

  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    17.63ms    7.86ms 102.29ms   87.71%
    Req/Sec    57.83      9.24    80.00     75.59%
  Latency Distribution
     50%   14.25ms
     75%   17.30ms
     90%   33.63ms
     99%   41.37ms
  1736 requests in 30.06s, 517.73MB read
Requests/sec:     57.75

After:

  Thread Stats   Avg      Stdev     Max   +/- Stdev
    Latency    16.96ms    9.48ms 145.37ms   88.17%
    Req/Sec    61.43      9.89    80.00     74.92%
  Latency Distribution
     50%   13.27ms
     75%   16.94ms
     90%   32.61ms
     99%   41.71ms
  1842 requests in 30.05s, 549.21MB read
Requests/sec:     61.30

This is pretty consistent over multiple runs. Seeing 1.04x - 1.07x


Claude is used to write documentation in encoding-test.c++.

@anonrig anonrig requested review from a team as code owners October 31, 2025 14:50
@codspeed-hq
Copy link

codspeed-hq bot commented Oct 31, 2025

Merging this PR will degrade performance by 21.41%

❌ 1 regressed benchmark
✅ 69 untouched benchmarks
⏩ 129 skipped benchmarks1

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

Performance Changes

Benchmark BASE HEAD Efficiency
bodyWithHeaders[Response] 30.2 µs 38.5 µs -21.41%

Comparing yagiz/experiment-value-view (9dce7c9) with main (f3b58ab)

Open in CodSpeed

Footnotes

  1. 129 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@anonrig anonrig force-pushed the yagiz/experiment-value-view branch from 30c0921 to 2259fce Compare October 31, 2025 17:18
@anonrig anonrig changed the title experiment with value view and simdutf improve text encoder encode performance Oct 31, 2025
@jasnell
Copy link
Collaborator

jasnell commented Nov 3, 2025

Looks like there are still some bugs to work out here with the failing CI... but even then, my preference would be to settle on #5449 first before landing any changes here. Also, since we do utf8 conversions everywhere, not just in TextEncoder::encode, my preference would be to address this more generally. That is, the optimized encoding path -- if we decide it's worthwhile -- should go into jsg::JsString so that it can be used everywhere rather than just in TextEncoder::encode.

@anonrig anonrig force-pushed the yagiz/experiment-value-view branch 2 times, most recently from 98afb46 to f1bbfe6 Compare November 3, 2025 17:15
@anonrig anonrig force-pushed the yagiz/experiment-value-view branch from 7fac631 to 681bf71 Compare November 3, 2025 17:50
@anonrig anonrig force-pushed the yagiz/experiment-value-view branch 3 times, most recently from 3a6ea76 to 6e3972e Compare November 3, 2025 20:04
@erikcorry
Copy link
Contributor

I don't think we need to speed optimize for the broken UTF-16 case unless and until someone shows it matters. The only reason to space-optimize would be to avoid throwing OOM, so if we can guarantee that doesn't happen I'm OK with some temporary blowup in space too.

@erikcorry
Copy link
Contributor

https://paste.cfdata.org/GKKdyFGFqSks

@anonrig
Copy link
Member Author

anonrig commented Nov 3, 2025

@anonrig anonrig force-pushed the yagiz/experiment-value-view branch from 1a2eab7 to 9f4fb86 Compare February 23, 2026 15:54
@anonrig anonrig force-pushed the yagiz/experiment-value-view branch from 9f4fb86 to d43ca36 Compare February 23, 2026 15:57
@codecov-commenter
Copy link

codecov-commenter commented Feb 23, 2026

Codecov Report

❌ Patch coverage is 71.24464% with 67 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.58%. Comparing base (f3b58ab) to head (9dce7c9).

Files with missing lines Patch % Lines
src/workerd/api/encoding-test.c++ 3.50% 0 Missing and 55 partials ⚠️
src/workerd/api/encoding.c++ 92.94% 2 Missing and 10 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5448      +/-   ##
==========================================
- Coverage   70.59%   70.58%   -0.01%     
==========================================
  Files         413      414       +1     
  Lines      109986   110195     +209     
  Branches    18120    18196      +76     
==========================================
+ Hits        77644    77782     +138     
- Misses      21531    21546      +15     
- Partials    10811    10867      +56     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants