Skip to content

Disable UTF-8 validity checks in parser for speed#552

Merged
Karolina-Bogacka merged 3 commits intomainfrom
piotr/faster-read-string
Sep 29, 2025
Merged

Disable UTF-8 validity checks in parser for speed#552
Karolina-Bogacka merged 3 commits intomainfrom
piotr/faster-read-string

Conversation

@Ostrzyciel
Copy link
Member

Using readString() any invalid UTF-8 characters are replaced with a UTF replacement char. That's also fine, because we don't actually have a contract saying that we must throw if invalid UTF-8 is encountered. This skips one check, making readString a bit faster:

# JMH version: 1.37
# VM version: JDK 25, Java HotSpot(TM) 64-Bit Server VM, 25+37-LTS-jvmci-b01
# VM invoker: /home/piotr/.jdks/graalvm-jdk-25/bin/java
# VM options: -XX:ThreadPriorityPolicy=1 -XX:+UnlockExperimentalVMOptions -XX:+EnableJVMCIProduct -XX:+EnableJVMCI -XX:-UnlockExperimentalVMOptions -Djacoco.skip=true
# Blackhole mode: compiler (auto-detected, use -Djmh.blackhole.autoDetect=false to disable)
# Warmup: 5 iterations, 10 s each
# Measurement: 10 iterations, 10 s each
# Timeout: 10 min per iteration
# Threads: 1 thread, will synchronize iterations
# Benchmark mode: Average time, time/op
# Benchmark: eu.neverblink.jelly.jmh.ReadStringBench.readString

Benchmark                              Mode  Cnt    Score   Error  Units
ReadStringBench.readString             avgt   10  747.251 ± 4.469  ns/op
ReadStringBench.readStringRequireUtf8  avgt   10  793.255 ± 1.196  ns/op

@codecov
Copy link

codecov bot commented Sep 28, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
see 2 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Karolina-Bogacka Karolina-Bogacka merged commit f3fbe01 into main Sep 29, 2025
12 checks passed
@Karolina-Bogacka Karolina-Bogacka deleted the piotr/faster-read-string branch September 29, 2025 07:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants