Details
-
Bug
-
Status: Open
-
Minor
-
Resolution: Unresolved
-
1.1
-
OS X 10.11.6
java version "1.8.0_60"
Java(TM) SE Runtime Environment (build 1.8.0_60-b27)
Java HotSpot(TM) 64-Bit Server VM (build 25.60-b23, mixed mode)
JProfiler 9.1 (Build 9128)
Description
There seams to be a small performance degradation on StringEscapeUtils.escapeJson(String) in commons-text v1.1 compared to commons-lang3 v3.5
I have a performance test that involves (amongst other things) escaping 200,052 strings. Using commons-text v1.1 this consistently takes 100ms to 110ms. Using commons-lang3 v3.5 this consistently takes 92ms to 95ms.
Also, after escaping I'm writing it to using java.io.Writer.write(String). I would have assumed that StringEscapeUtils.ESCAPE_JSON.translate(CharSequence, writer) would yield better performance, however in the same test, using this method constantly takes approx 210ms and the parent method (which serialises the entire payload to JSON) takes approx 1750ms compared to approx 1400ms using StringEscapeUtils.escapeJson(String) from commons-lang3 v3.5
I've marked the issue as minor, as it doesn't really impact me, but I thought I should share my findings.
The serialiser can be found at https://github.com/mountain-pass/ryvr/blob/master/src/main/java/au/com/mountainpass/ryvr/io/RyvrSerialiser.java and the performance test can be executed using `./gradlew testRyvrTests_Integration_Performance_Java_H2Local`
Also, I should mention that StringEscapeUtils.escapeJson is an order of magnitude faster than the equivalents from:
- org.json:json:20170516
- org.unbescape:unbescape:1.1.5.RELEASE
- com.googlecode.json-simple:1.1.1
- net.minidev:son-smart:2.3
They literally take over 1000ms to do what StringEscapeUtils.escapeJson() does in about 100ms. If there are any other libs you would like me to test against for comparison purposes, please let me know.