japplis opened a new pull request, #541:
URL: https://github.com/apache/commons-vfs/pull/541

   I've noticed using JFR for performance profiling that 
`AbstractFileObject.getChildren()` was spending most of the time in 
`StringBuilder.substring()` done in the `UriParser.PathNormalizer` class.
   See attached flamegraphs.
   
![profiling-UriParser-crop](https://github.com/apache/commons-vfs/assets/318821/80c9b0aa-6337-4355-ba01-dd2ad67befbd)
   
   Looking at the code, I first notice that the substring that was using the 
most of time was incorrect as it was producing a String of length 2 and we were 
comparing it with a String of length 3.
   I've added a private method `isCursorAtUrlEncodedSlash()` to perform the 
test for %2f using `charAt` instead of `substring` and at the same time fix the 
invalid comparaison.
   
   After fixing the test in '`readNonSeparators()`', a unit test failed:
   `NamingTests` -> `assertSameName(path, name, "foo%2f..%2fa", scope);`
   The reason was before the fix the resolved path was 
'/Java/libraries/commons-vfs/commons-vfs2/target/test-classes/test-data/read-tests/foo%2f..%2fa'
   After the fix the resolved path is 
'/Java/libraries/commons-vfs/commons-vfs2/target/test-classes/test-data/read-tests%2fa'
   `AbstractFileName.checkName` (with scope child) wasn't failing first as 
`path.charAt(baseLen)` was '/' (the '/' before foo)
   then it was failing as the separator at baseLen was %2f and not '/'.
   So I've changed the `UriParser.PathNormalizer.readSeparator()` to also 
normalize the '%2f' to '/'. This fixes the unit tests.
   
   At the same time, I've replaced the other not needed 
`StringBuilder.substring` of `UriParser` with `StringBuilder.charAt` as 
profiling data (See attached flamegraph) was showing performance costs in 
`readDot`.
   
![profiling-UriParser2-crop](https://github.com/apache/commons-vfs/assets/318821/cb44ca9a-a5c6-4f28-ba1c-08433324093f)
   
   I've also removed the `readToNextSeparator()` as it was the exact same code 
as `readNonSeparators()`


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to