nfsantos opened a new pull request, #3146:
URL: https://github.com/apache/jackrabbit-oak/pull/3146

   https://issues.apache.org/jira/browse/OAK-12411
   
   `Template.hashCode()` currently recomputes its hash on every call via 
`Objects.hash(primaryType, mixinTypes, Arrays.asList(properties), 
getTemplateType(), childName)`, which allocates a varargs `Object[]` and a 
`List` wrapper around `properties` on every invocation.
   
   `Template` is immutable once constructed, so the hash code can be computed 
once and cached, following the same lazy-caching pattern as 
`java.lang.String#hashCode()`:
   * A field initialized to `0` means "not yet computed".
   * A benign race across threads just recomputes the same value; no 
synchronization needed.
   
   This removes the per-call allocation, which matters because 
`Template.equals()`/`hashCode()` are used for template deduplication during 
node writes — one of the hotter paths in `DefaultSegmentWriter`.
   
   No behavioral change intended; the `equals()`/`hashCode()` contract is 
preserved.
   
   ## Test plan
   - [x] `mvn -pl oak-segment-tar test 
-Dtest=TemplateTest,DefaultSegmentWriterTest` passes


-- 
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