question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Performance bottlenecks

See original GitHub issue

I am observing high cpu usage due to extensive usage of JsonPath. Using Java Flight Recording to profile a production machine, these areas standout in JProfiler as cpu hotspots.

  1. JsonPath.getPath() This method recursively evaluates the PathToken to build the string representation. In one case we have this in a TreeSet to sort the order of evaluations, and the comparator is surprisingly expensive. Since the JsonPath is compiled and cached, it would make sense for the string representation to be lazily cached (ala String’s hashCode). It may also be faster to replace recursive descent with a loop.

  2. JsonContext.pathFromCache(path) This method very inefficiently computes the cache key, resulting in excessive cpu and allocations.

    • When there are no filters, then the path can be used directly as the key.
    • Because the filters is a second arg, “[]”, the concat slow path is used.
    • There is no reason to wrap a list with a LinkedList, as they have the same toString implementation.
    • Arrays.toString would be a more efficient conversion.
    • The operation could use a computeIfAbsent to avoid redundant work on a cache miss due to races.
  3. JsonPath.compile(path) This user-facing method creates a new JsonPath instead of using the cache. Therefore if one tries to optimize to bypass the slow pathFromCache call, there is high overhead. The compilation should return the cached copy, allowing the application user to benefit from the configured cache.

  4. JsonPath.read(Object, Configuration) This method uses exceptions as ordinary control flow. That is a bad practice because it is slow when many exceptions are created, as filling the stack trace is a costly operation. The internals should return a result object which could be evaluated to the suppressed value.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:2
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

2reactions
ben-manescommented, Sep 8, 2021

Yes, I think you are finding the same problem as my 4th item. The exception for control flow is pretty bad, as you show.

1reaction
richardstartincommented, Mar 2, 2022

I think these issues are mostly addressed in the latest release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Identifying Performance Bottlenecks
One of the keys to successful deployment design is identifying potential performance bottlenecks and developing a strategy to avoid them.
Read more >
Performance testing 101: Finding and fixing bottlenecks
Performance testing is less about finding bugs in the software and more about identifying and removing performance bottlenecks. Bottlenecks are ...
Read more >
How to Steer Clear of Application Performance Bottlenecks
In software engineering, a bottleneck occurs when the capacity of an application or a computer system is limited by a single component, like...
Read more >
The 5 Most Common PC Bottlenecks - Apica
Performance bottlenecks can lead an otherwise functional computer or server to slow down to a crawl. The term “bottleneck” refers to both an ......
Read more >
Common performance bottlenecks in a web application server
Bottleneck #1: database queries · Never execute a database query inside a loop · Perform joins or aggregation lookups with indexed fields ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found