AER-4590 Avoid redundant work in JSONObjectHandle - #82
Merged
Merged
Conversation
has() built the key set twice per call and discarded both; getStringOrDefault allocated a wrapper around its own inner object to call a method on itself.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



This contains some proven non-controversial optimizations in the JSON parser framework.
LLM-generated technical summary
Two changes in
JSONObjectHandle, both provably equivalent.has()enumerated the object twice per call. It was:keySet()delegates to GWT'sJSONObject.keySet(), which on every call runs a fullfor-inwithhasOwnProperty, allocating a freshString[]and an anonymousAbstractSet. Nothing is cached —size()even carries a comment about having to recheck for foreign changes.Crucially, the returned set overrides
containsto delegate straight back tocontainsKey, so the key array it just built is never read:So both enumerations were pure waste, and
inner.containsKey(key)reaches the identical nativekey in jsObject. Equivalence holds by construction rather than by argument, including for keys whose value is JSON null and for prototype-chain names such astoString(whichhas()already reported as present — that pre-existing quirk is preserved).keySet()can never return null, so that guard was dead. Akey != nullcheck was added to keephas(null)returning false: without it,null in jsObjectcoerces to the property name"null".In one AERIUS Calculator boot this is called ~15,400 times, so ~30,800 object enumerations disappear.
getStringOrDefaultallocated a wrapper around its own state. It callednew JSONObjectHandle(inner).getString(key).inneris the class's only field and the constructor merely assigns it, so the new instance was identical tothis;getString(key)is the same call without the allocation.Verified against the GWT sources shipped in
org.gwtproject:gwt-user:2.13.1;JSONObject.javais byte-identical across 2.10.0, 2.12.1, 2.13.0 and 2.13.1, so this does not depend on the GWT version in use.Two things a reviewer should know. The module contains no test files, so
mvn testpasses having run nothing — compilation is the only automated evidence here, and real validation is a client boot. And the runtime saving has not been measured in a browser; the change is justified by strictly removing work, not by a benchmark.