Fixed
Details
Assignee
Alex MillerAlex MillerReporter
Erik AssumErik AssumPriority
Major
Details
Details
Assignee
Alex Miller
Alex MillerReporter
Erik Assum
Erik AssumPriority

Created March 12, 2021 at 8:54 AM
Updated March 18, 2021 at 9:39 PM
Resolved March 18, 2021 at 9:39 PM
Todays implementation looks at each char in a string, and appends that to a
StringBuilder
according to certain rules. This is needed in order to handle unicode and escaped characters.This leaves room for an optimization if we observe that most strings we write will be unescaped and within ascii range.
See 163-cpu-flamegraph-2021-03-12-12-47-10.svg for evidence of this
Approach:
Split
write-string
in a fast path and a slow path. As long as we only see unescaped ascii chars, we stay on the fast path and write the string directly to thePrintWriter
. As soon as we see anything else, we use the old implementation ofwrite-string
to deal with it.Benchmark:
This is based applying the patch from
10b
100b
1k
10k
100k
728.014454 ns
3.693765 µs
18.908001 µs
257.675705 µs
2.331272 ms
See 183-cpu-flamegraph-2021-03-12-13-21-48.svg for flame graph after patch applied
Patch:
0001-DJSON-34-Speed-up-writing-strings.patch
Approach 2 Consolidate String writing
Don’t split the string writing. This also solves
Benchmark:
10b
100b
1k
10k
100k
752.902385 ns
3.652398 µs
19.260306 µs
217.215371 µs
2.078711 ms
Patch:
0002-DJSON-34-Speed-up-writing-strings.patch