Skip to content

[Perf] node() re-serialises and re-parses the entire tree on every call #47

Description

@egg82

What problem are you trying to solve?

Lib/src/main/java/me/egg82/arr/common/AbstractFetchableAPIObject.java:24

return new JsonNode(node.toString());

A full serialise to String plus a full re-parse into a second tree, to hand back a defensive copy.

On a 65 MB tree that measured 335-547 ms and another full-size tree per call. It lands on the cache-write path, so roughly hourly per instance rather than every cycle - Movie.cacheTime() is 65 minutes against a 1 hour default interval.

Both real callers are writeCache, at AbstractArrAPI.java:276 and :314, and both do the same thing: serialise it straight back out to the cache file and drop it. Neither needs isolation from the original.

What would you like Fetcharr to do?

Handing the tree to something that immediately serialises it shouldn't cost a full copy of it first.

Return the reference. If some caller genuinely needs isolation, give that caller an explicit copy() rather than charging every caller for one.

This overlaps with the retained-tree issue - if writeCache takes the tree directly instead of calling node(), both problems go away together.

Optional additional context or use case that could be helpful

node() is on the public FetchableAPIObject interface, so changing what it returns is a contract change even though nothing in-tree depends on the copy.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions