-
Notifications
You must be signed in to change notification settings - Fork 626
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Rewrite and restructure JSON parser #1343
Conversation
* Get rid of spontaneous lookahead * Spill fewer variables into object state * Optimize token and whitespaces reading * Separate fast and slow paths * Add optimistic key consumption optimization to leverage indexOf intrinsic * Improve exception messages in few places All tests except lenient boolean should pass Benchmark difference for throughput (Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz, libraries-linux-perf-unit-877): CitmBenchmark.decodeCitm diff +8% CoerceInputValuesBenchmark.testNonNullableCoercing diff +11% CoerceInputValuesBenchmark.testNonNullableRegular diff +5% CoerceInputValuesBenchmark.testNullableCoercing diff +7% CoerceInputValuesBenchmark.testNullableRegular diff +13% JacksonComparisonBenchmark.kotlinFromString diff +16% (noisy, JUT-dependable) TwitterBenchmark.parseTwitter diff +26% TwitterFeedBenchmark.parseTwitter diff +30%
18de55e
to
9a0277a
Compare
7117dcd
to
269d3d3
Compare
…ting over the source
269d3d3
to
e9d4d3e
Compare
…here they are not really necessary It gives solid 5-10% of throughpuut
003f59e
to
9fd2412
Compare
01b907b
to
aa4ae97
Compare
* Replace handrolled char-array with StringBuilder, tweak it here and there * Always use optimistic path for strings * Properly handle slow-path from the middle of a string
aa4ae97
to
9b97996
Compare
benchmark/src/jmh/kotlin/kotlinx/benchmarks/json/CoerceInputValuesBenchmark.kt
Show resolved
Hide resolved
benchmark/src/jmh/kotlin/kotlinx/benchmarks/json/PrimitiveValuesBenchmark.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/JsonElementSerializers.kt
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/JsonReader.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/JsonReader.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt
Outdated
Show resolved
Hide resolved
formats/json/jvmTest/src/kotlinx/serialization/json/GsonCompatibilityTest.kt
Show resolved
Hide resolved
* Better exception messages and hints * Minor improvements * More comments
formats/json/commonMain/src/kotlinx/serialization/json/internal/JsonReader.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/JsonReader.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/JsonReader.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt
Outdated
Show resolved
Hide resolved
formats/json/commonMain/src/kotlinx/serialization/json/internal/JsonReader.kt
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job!
NB: it just came to my mind that JsonLexer
is far more better name than JsonReader
(since we already have JsonParser
). If you feel the same, you can rename it as a part of this PR.
formats/json/commonMain/src/kotlinx/serialization/json/internal/StreamingJsonDecoder.kt
Outdated
Show resolved
Hide resolved
# Conflicts: # benchmark/src/jmh/kotlin/kotlinx/benchmarks/json/TwitterBenchmark.kt
@qwwdfsad my app heavily utilize CPU - ~15% from all cores and more shows in Htop. Even worse on mobile devices. After your two PRs CPU usage was reduced to ~10%. It's awesome! Thank you for your findings! |
Benchmark improvements for throughput (Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz, libraries-linux-perf-unit-877):