perf: skip escape scan for AsciiSafeStr in the char renderer#878
Open
He-Pin wants to merge 1 commit into
Open
Conversation
2 tasks
The char render path (BaseCharRenderer.visitNonNullString) ran a CharSWAR.hasEscapeChar scan on every string, even for Val.AsciiSafeStr which is statically known to need no JSON escaping (chars 0x20-0x7e, no quote/backslash). The Native ByteRenderer already had this bypass; the char path did not. - Add BaseCharRenderer.visitAsciiSafeString: quote + bulk getChars + quote, correct even under escapeUnicode since all chars are <= 0x7e. - Route Val.AsciiSafeStr through it via a Materializer.visitStr helper at the three value-string sites; the ujson.Value AST path falls back to visitString. Result: - JMH render-only (string-heavy, 335 KB): 1.606 -> 1.441 ms/op (+10%). - Scala Native, isolated and interleaved: manifestJsonEx total_time 30.6 -> 29.5 ms (~+3.6%); kube-prometheus materialize_time neutral. Output byte-identical.
0aa826f to
a538958
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation
The char render path (
BaseCharRenderer.visitNonNullString) ran aCharSWAR.hasEscapeCharscan on every string, even forVal.AsciiSafeStr— which is statically known to need no JSON escaping (chars0x20–0x7e, no"/\). The NativeByteRendereralready had this bypass; the char path did not.Modification
BaseCharRenderer.visitAsciiSafeString:"+ bulkgetChars+", correct even underescapeUnicodesince every char is<= 0x7e.Val.AsciiSafeStrthrough it via aMaterializer.visitStrhelper at the three value-string sites; theujson.ValueAST path falls back tovisitString.Result
manifestJsonExtotal_time 30.6 → 29.5 ms (~+3.6%); kube-prometheusmaterialize_timeneutral (no regression). Output byte-identical.Test plan
./mill __.reformat./mill 'sjsonnet.jvm[3.3.7]'.test— 518/518 pass