[ 
https://issues.apache.org/jira/browse/TAP5-2837?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18128172#comment-18128172
 ] 

Hudson commented on TAP5-2837:
------------------------------

FAILURE: Integrated in Jenkins build Tapestry ยป tapestry-5.9.x-javax-freestyle 
#3 (See 
[https://ci-builds.apache.org/job/Tapestry/job/tapestry-5.9.x-javax-freestyle/3/])
TAP5-2837: Improve JSON serialization performance (#67) (thiago: rev 
0d1fbd89b7f7913f9b845a90ec9299c9c966ab1f)
* (edit) 
tapestry-json/src/main/java/org/apache/tapestry5/json/PrettyPrintSession.java
* (add) 
tapestry-json/src/test/java/org/apache/tapestry5/json/JSONObjectTest.java
* (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONTokener.java
* (add) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONPrintSink.java
* (edit) 
tapestry-json/src/main/java/org/apache/tapestry5/json/JSONCollection.java
* (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/package-info.java
* (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONStringer.java
* (edit) tapestry-json/src/main/java/org/apache/tapestry5/json/JSONObject.java
* (edit) 
tapestry-json/src/main/java/org/apache/tapestry5/json/CompactSession.java


> Improve JSON serialization performance (toString/toCompactString)
> -----------------------------------------------------------------
>
>                 Key: TAP5-2837
>                 URL: https://issues.apache.org/jira/browse/TAP5-2837
>             Project: Tapestry 5
>          Issue Type: Improvement
>          Components: tapestry-json
>            Reporter: Ben Weidig
>            Assignee: Ben Weidig
>            Priority: Minor
>             Fix For: 5.9.2
>
>          Time Spent: 20m
>  Remaining Estimate: 0h
>
> h3. Overview
> {{JSONObject}}/{{JSONArray}}'s {{toString()}} and {{toCompactString()}} are 
> slower than necessary due to synchronization overhead and per-{{String}} 
> allocation in the print path.
> My sandbox implementation at 
> https://github.com/benweidig/tapestry-json-improvements (non-breaking, 
> verified byte-for-byte against current output) shows a ~4-6x speedup across 
> payload sizes and both compact/pretty formatting, with no public API changes.
> h3. Problem
> * {{toString()}}/{{toCompactString()}} route output through 
> {{CharArrayWriter}} wrapped in {{PrintWriter}}, both use {{synchronized}} 
> methods on every write. This is pure overhead for single-threaded string 
> building.
> * {{JSONObject.quote(String)}} allocates a new {{JSONStringer}} (own 
> {{StringBuilder}} + {{ArrayList}} scope stack) for every quoted string, like 
> keys and string values in a payload.
> * Extended-Unicode escaping goes through {{String.format}}, which parses the 
> format string on every call.
> * Output buffers start at JDK default capacity with no pre-sizing, causing 
> repeated grow/copy for larger trees.
> h3. Proposed changes
> Delete {{JSONStringer}} and inline its escaping loop directly into 
> {{JSONObject}} as a static {{escapeInto(...)}} helper, called directly by 
> {{quote()}} and the print sessions.
> Replace {{String.format}} hex escaping with manual nibble extraction + lookup 
> table.
> Drop {{CharArrayWriter}}/{{PrintWriter}} for 
> {{toString()}}/{{toCompactString()}}.
> Instead, build directly into a {{StringBuilder}}.
> Pre-size the output buffer based on collection size instead of the JDK 
> default.
> All changes are additive/internal/package-private only, without any no 
> signature changes, no behavior changes.
> Full test suite plus a new baseline-equivalence test confirmed identical 
> output to 5.9.1 in my sandbox.
> h3. Risks
> * Low functional risk: escaping logic is a straight extraction/refactor, 
> covered by existing tests.
> * Removing {{JSONStringer}} is a *breaking change* for any external caller 
> referencing that class directly (it's currently public): Needs a 
> compatibility/deprecation decision before merge.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to