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

Improve performance of UnresolvedForwardReference for forward reference resolution #3419

Closed
morganga opened this issue Mar 18, 2022 · 2 comments · Fixed by #3422
Closed

Improve performance of UnresolvedForwardReference for forward reference resolution #3419

morganga opened this issue Mar 18, 2022 · 2 comments · Fixed by #3422
Milestone

Comments

@morganga
Copy link
Contributor

JsonMappingException is a checked exception used to signal fatal problems with mapping of content.

UnresolvedForwardReference, which extends JsonMappingException is thrown and caught internally for completely VALID json to resolve forward references.

Throwable.fillInStackTrace() is an expensive operation, it's the main cost of throwing most Exceptions, and it's called for all UnresolvedForwardReference thrown and caught internally. The stackTrace is irrelevant for these internal exceptions, it is wasted computation.

The json documents we process are full of object references, so I took the liberty of locally redefining UnresolvedForwardReference to extend RuntimeException, and using the RuntimeException constructor to set writableStackTrace to false, bypassing the Throwable.fillInStackTrace() call.
I noticed speed improvements of 50%, deserialization takes half the time when Throwable.fillInStackTrace() is turned off for our typical json payloads.

DeserializationContext does have a method checkUnresolvedObjectId(), which throws the genuine fatal unresolved forward references.

All I'm asking is that UnresolvedForwardReference thrown and caught internally are created with writableStackTrace = false, whether that's achieved by supplying new parent constructors to pass the flag up the hierarchy, or creating a new exception type that's only used internally to report a forward reference to be resolved later, It need not be a breaking change, only an internal performance improvement.

@cowtowncoder
Copy link
Member

+1 for such work: contribution would be very welcome! Yes, I know exception construction is expensive mostly due to stack trace calculations.
PR should probably be against 2.14, although if change seems very safe I would accept it against 2.13 -- the main criteria (after API changes which cannot go in a patch) is the perceived risk of regression.

morganga added a commit to morganga/jackson-databind that referenced this issue Mar 20, 2022
morganga added a commit to morganga/jackson-databind that referenced this issue Mar 21, 2022
cowtowncoder pushed a commit that referenced this issue Mar 22, 2022
@cowtowncoder cowtowncoder changed the title UnresolvedForwardReference performance improvement for forward reference resolution Improve performance of UnresolvedForwardReference for forward reference resolution Mar 22, 2022
@cowtowncoder cowtowncoder added this to the 2.14.0 milestone Mar 22, 2022
cowtowncoder added a commit that referenced this issue Mar 22, 2022
@cowtowncoder
Copy link
Member

Merged, will be included in 2.14.0. Thank you @morganga!

cowtowncoder added a commit that referenced this issue Apr 5, 2022
@cowtowncoder cowtowncoder modified the milestones: 2.14.0, 2.13.3 May 14, 2022
@cowtowncoder cowtowncoder added 2.13 and removed 2.14 labels May 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants