simdjson-java icon indicating copy to clipboard operation
simdjson-java copied to clipboard

Does it not support multithreading?

Open wycst opened this issue 1 year ago • 4 comments

Hello, the project is very good. Recently, during testing with JMH, it was found that errors occur in multi-threaded environments. Does it currently not support multi-threaded concurrency?

wycst avatar Nov 27 '24 06:11 wycst

Hello, the SimdJsonParser is not thread-safe. However, you can create a dedicated instance for each thread and store it in a thread-local field. This should work well in multi-threaded environments.

piotrrzysko avatar Jan 12 '25 10:01 piotrrzysko

Hello, the SimdJsonParser is not thread-safe. However, you can create a dedicated instance for each thread and store it in a thread-local field. This should work well in multi-threaded environments.

Hello, would you mind adding the wast library( https://github.com/wycst/wast )Compare performance

implementation("io.github.wycst:wast:0.0.23")

DOM Parser

List<JSONNode> users = JSONNode.collect(buffer, "/statuses/*/user");
Set<String> defaultUsers = new HashSet<>();
for (JSONNode user : users) {
    if (user.getChildValue("default_profile", boolean.class)) {
        defaultUsers.add(user.getChildValue("screen_name", String.class));
    }
}
return defaultUsers.size();

Schema-Based Parser

Set<String> defaultUsers = new HashSet<>();
SimdJsonTwitter twitter = io.github.wycst.wast.json.JSON.parseObject(buffer, SimdJsonTwitter.class);
for (SimdJsonStatus status : twitter.statuses) {
    SimdJsonUser user = status.user;
    if (user.default_profile) {
        defaultUsers.add(user.screen_name);
    }
}
return defaultUsers.size();

wycst avatar Feb 07 '25 16:02 wycst

Hi, have you run the benchmarks? If so, could you share the results?

piotrrzysko avatar Feb 26 '25 19:02 piotrrzysko

Hi, have you run the benchmarks? If so, could you share the results?

Test code https://github.com/wycst/wast-jmh-test/blob/main-openjdk23/src/main/java/com/jmh/test/simdjson/TwitterJmhTest.java

The result of running on the Windows platform (window10 + i5 + JDK 21) https://github.com/wycst/wast-jmh-test/blob/main-openjdk23/WastJson_vs_SimdJson_TwitterJmhTest_2024_11_27_RAW.md

Benchmark Mode Cnt Score Error Units TwitterJmhTest.parseAndSelect_SimdjsonJava thrpt 5 1370.652 ± 37.171 ops/s TwitterJmhTest.parseAndSelect_WastJson thrpt 5 1997.455 ± 275.386 ops/s TwitterJmhTest.schemaBasedParseAndSelect_SimdjsonJava thrpt 5 2092.163 ± 98.596 ops/s TwitterJmhTest.schemaBasedParseAndSelect_WastJson thrpt 5 2654.975 ± 102.240 ops/s

wycst avatar Feb 27 '25 07:02 wycst