Project

Profile

Help

Bug #6565

closed

Performance Regression in DocumentFn with Java 12 or higher

Added by Philipp Nanz about 1 month ago. Updated 15 days ago.

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

0%

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

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 about 1 month 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 about 1 month ago

Thanks for this useful information.

Actions #3

Updated by Philipp Nanz about 1 month 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 about 1 month 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 about 1 month 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

Actions #6

Updated by Michael Kay 15 days ago

  • Category set to Performance
  • Status changed from New to Resolved
  • Assignee set to Michael Kay
  • Applies to branch trunk added
  • Fix Committed on Branch 12, trunk added
  • Platforms Java added

Needed to do a bit of extra tweaking to make the new code transpile to C#.

Please register to edit this issue

Also available in: Atom PDF