Skip to content
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

upgrade fastjson to 2.0.51 #104

Merged
merged 4 commits into from
Jun 11, 2024
Merged

Conversation

wenshao
Copy link
Contributor

@wenshao wenshao commented May 12, 2024

fastjson 2.0.50 once again improves performance. fastjson 2.0.50 provides configuration parameters that do not generate unnecessary code during JIT to improve performance. Configuration parameters can be set through the API or configured through JVM startup parameters.

This PR upgrades the fastjson version and enables JVM startup parameters to improve performance.

run Outdated
@@ -3,7 +3,7 @@
JAR=build/libs/app.jar
HEAP_SIZE=2g

[ -z ${JVM_OPTIONS} ] && JVM_OPTIONS="-server -Xms${HEAP_SIZE} -Xmx${HEAP_SIZE} --add-opens=java.base/java.time=ALL-UNNAMED --add-modules=jdk.incubator.vector"
[ -z ${JVM_OPTIONS} ] && JVM_OPTIONS="-server -Xms${HEAP_SIZE} -Xmx${HEAP_SIZE} --add-opens=java.base/java.time=ALL-UNNAMED --add-modules=jdk.incubator.vector -Dfastjson2.features=disableReferenceDetect,disableArrayMapping,disableJSONB,disableAutoType,disableSmartMatch"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these fastjson2 options documented somewhere? and why they are safe to use in a production environment? Why would they not be set by default if they are safe?

Moreover, it would be preferable to introduce Java code/class (via System.setProperty) to increase the visibility that these options are used, and optionally to find a way to run fastjson2_optimized vs fastjson2_default.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fastjson provides many functions that other json libraries do not have. These options can be turned off on demand and can be used in a production environment. There is a Chinese document introducing it.

The current version only supports global opening or closing. Serde that provides per-instance configuration options will be provided in the next version (2.0.51)

Copy link
Owner

@fabienrenaud fabienrenaud May 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's wait for 2.0.51 then. When it's ready, let's introduce a new FASTJSON2_OPTIMIZED implementation in Library, etc. so default vs optimized fastjson2 can be compared side by side (jackson has 3 such cases).
I read the docs and using these flags seem to require in-depth knowledge of certain fastjson2 features to be useful, so best to keep it isolated from the default fastjson2 behavior (whatever that may be).

@Philzen Philzen mentioned this pull request May 26, 2024
4 tasks
@wenshao wenshao force-pushed the fastjson_2_0_50 branch from f1d5705 to 486b088 Compare June 1, 2024 11:19
@wenshao wenshao changed the title upgrade fastjson to 2.0.50 upgrade fastjson to 2.0.51 Jun 1, 2024
@wenshao
Copy link
Contributor Author

wenshao commented Jun 1, 2024

It has been updated to version 2.0.51, and non-default test methods have been added

Copy link
Owner

@fabienrenaud fabienrenaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run the benchmark showing both fastjson2 and fastjson2_features results for ser and deser.

README.md Outdated Show resolved Hide resolved
static final ObjectReaderProvider featuresProvider = new ObjectReaderProvider();
static final JSONReader.Context featuresContext;
static {
featuresProvider.setDisableArrayMapping(true);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot find such methods when searching on github / fastjson2. Can you provide a link to show me where these are published/pushed?

@wenshao
Copy link
Contributor Author

wenshao commented Jun 11, 2024

Please run the benchmark showing both fastjson2 and fastjson2_features results for ser and deser.

./run deser --apis databind --libs fastjson --size 1000
Benchmark                           Mode  Cnt     Score   Error  Units
Deserialization.fastjson           thrpt   20  1089.563 ? 6.804  ops/s
Deserialization.fastjson_features  thrpt   20  1129.553 ? 8.832  ops/s

./run ser --apis databind --libs fastjson --size 1000
Benchmark                         Mode  Cnt     Score    Error  Units
Serialization.fastjson           thrpt   20  1511.359 ? 10.985  ops/s
Serialization.fastjson_features  thrpt   20  1549.062 ? 27.393  ops/s

Copy link
Owner

@fabienrenaud fabienrenaud left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! Thank you for the contribution.

@fabienrenaud fabienrenaud merged commit 64083f7 into fabienrenaud:master Jun 11, 2024
1 check passed
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