Project

Profile

Help

Bug #6565

open

Performance Regression in DocumentFn with Java 12 or higher

Added by Philipp Nanz 4 days ago. Updated 3 days ago.

Status:
New
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2024-10-21
Due date:
% Done:

0%

Estimated time:
Legacy ID:
Applies to branch:
12
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:

Description

Hello,

I have come across a slow-down that is happening when accessing files using fn:document or checking for their existence using fn:doc-available.

I have also attached a screenshot of the hotspot (taken from JProfiler). The bottom line seems to be that with current Java versions File.getCanonicalPath is much slower, due to a cache that was removed from JDK.

Here are some links related to the change: https://bugs.openjdk.org/browse/JDK-8207005 https://bugs.java.com/bugdatabase/view_bug?bug_id=8309215

The was first disabled with Java 12, and then completely removed with Java 21.

From the looks of it, DocumentFn is only using it to conveniently normalize the filename. perhaps there is a way to do that without the need to call getCanonicalPath() .

Thanks in advance and kind regards, Philipp


Files

hotspot.png (111 KB) hotspot.png Philipp Nanz, 2024-10-21 15:08
SaxonDocumentKeyFix.java (2.1 KB) SaxonDocumentKeyFix.java Philipp Nanz, 2024-10-23 10:13
Actions #1

Updated by Philipp Nanz 4 days ago

When using the Java system property "-Dsun.io.useCanonCaches=true" on Java 17, the hotspot is also solved.

Actions #2

Updated by Michael Kay 4 days ago

Thanks for this useful information.

Actions #3

Updated by Philipp Nanz 3 days ago

We have looked into this in more detail and have come up with a solution by modifying the code at runtime using bytecode manipulation. I attach our solution, we have profiled it and it solves the problem. Note: The used solution uses Java NIO API, which is only available in Java 7 and higher.

Hope this helps!

Actions #4

Updated by Michael Kay 3 days ago

Many thanks for this!

Could you please confirm that you understand the terms and conditions for the site in particular the paragraph:

When you post code fragments on this site, then unless clearly specified otherwise, you implicitly give Saxonica Ltd license to use these code fragments in its test suite; and if the code fragments represent suggested changes to the code of a Saxonica product, to use the code fragments in future versions of the product.

Actions #5

Updated by Philipp Nanz 3 days ago

Yes, I can confirm that. In fact, I would be more than happy if this change makes it back into Saxon :-)

Thanks and kind regards, Philipp

Please register to edit this issue

Also available in: Atom PDF