On Mon, 25 Jan 2021 00:05:52 GMT, Claes Redestad <[email protected]> wrote:

> This patch optimizes the code paths exercised by 
> `String.class.getResource("String.class")` by:
> 
> - Adding an ASCII fast-path to methods verifying strings in the jimage, which 
> can then be done allocation-free
> - Avoiding the allocation of the `long[8]` attributes when verifying only for 
> the purpose of verifying a path exists
> - Using the `JNUA.create` fast-path in `SystemModuleReader` (which should be 
> OK since we just verified the given name is a JRT path)
> - Remove a redundant check in `Class::resolveName` and fitting the 
> `StringBuilder` to size

On the provided benchmark we can observe a 2x speed-up and a 70% reduction in 
allocation.

Baseline:
Benchmark                                                      Mode  Cnt     
Score     Error   Units
ClassGetResource.stringClass                                   avgt    5  
2885.403 ± 309.787   ns/op
ClassGetResource.stringClass:·gc.alloc.rate.norm               avgt    5  
1368.124 ±   0.056    B/op

Patch:
Benchmark                                                      Mode  Cnt     
Score     Error   Units
ClassGetResource.stringClass                                   avgt    5  
1411.980 ± 155.877   ns/op
ClassGetResource.stringClass:·gc.alloc.rate.norm               avgt    5   
408.038 ±   0.043    B/op

-------------

PR: https://git.openjdk.java.net/jdk/pull/2212

Reply via email to