Repository navigation
Copy the leading ASCII run in bulk when converting Latin-1 to rust::String - #8016
Conversation
|
✅ Approved — No issues found. The new Latin-1 to UTF-8 fast path is correct: the unchecked UTF-8 conversion only ever sees bytes that were checked to be ASCII, and the reserved capacity matches the exact output length. The decision is advisory: this comment never approves, blocks or requests changes on the pull request. ✅ All checks passed📋 Code Quality: ✅ LGTMI found no problems in the new
📝 Documentation: ✅ LGTMI found no documentation problems. The new comments describe what the code does now, as the repository's comment guidelines ask. Reviewed commit: |
|
Since last review: 0 resolved, 0 still open, 0 new. Reviewed commit: 232dde4a · github run |
…tring rust::String::latin1() pushed every byte as a char, one at a time. Rust JSG converts every one-byte string argument this way, so a 64 KiB ASCII string took 24.8 us, against 2.0 us in C++ JSG. In this patch string_from_latin1 finds the leading ASCII run 32 bytes at a time, copies it in bulk and encodes only the rest per character. It also reserves the exact UTF-8 length, so non-ASCII strings no longer regrow while being built. CPU time per call to a method taking a string (bench-jsg from #8013, --config=benchmark, 5 processes x 5 reps): case before after C++ JSG ascii/16 46.9 ns 45.6 ns 28.5 ns ascii/1024 445.5 ns 78.4 ns 54.8 ns ascii/65536 24.8 us 1.80 us 2.04 us latin1/16 70.7 ns 51.3 ns 33.4 ns latin1/65536 33.9 us 34.9 us 31.8 us
301b03e to
232dde4
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #8016 +/- ##
==========================================
- Coverage 42.05% 41.96% -0.10%
==========================================
Files 1061 1064 +3
Lines 301008 302174 +1166
Branches 29043 29082 +39
==========================================
+ Hits 126599 126803 +204
- Misses 157389 158340 +951
- Partials 17020 17031 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
rust::String::latin1()pushed every byte as a char. Rust JSG converts every one-byte string argument this way, so a 64 KiB ASCII string took 24.8 µs vs 2.0 µs in C++ JSG.In this patch the leading ASCII run is found 32 bytes at a time and copied in bulk, and only the rest is encoded per character. The exact UTF-8 length is reserved up front.
CPU time per call (bench-jsg from #8013,
--config=benchmark, 5 processes × 5 reps):