[ 
https://issues.apache.org/jira/browse/OAK-12417?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Nuno Santos updated OAK-12417:
------------------------------
    Description: 
{{AbstractRemoteSegmentArchiveReader#readSegment(long, long)}} and 
{{#containsSegment(long, long)}} are called once per segment reference and are 
on the hot path of online compaction. They currently look up a {{Map<UUID, 
RemoteSegmentArchiveEntry>}}, which requires allocating a new {{UUID}} object 
for every call just to use as a lookup key, plus paying for 
{{UUID.hashCode()}}/{{equals()}} through a generic {{HashMap}}.
* Add a small, package-private open-addressing map ({{SegmentIndex}}) keyed 
directly on the raw {{(msb, lsb)}} long pair, built once per archive open 
({{SegmentIndex.Builder}}, not on a hot path) and queried without any 
per-lookup allocation.
* {{AbstractRemoteSegmentArchiveReader}} is updated to use it instead of a 
{{UUID}}-keyed map. {{getSegmentUUIDs()}} (not on the hot path) still returns 
{{UUID}}s, built lazily from the index's entries by reusing each entry's 
existing {{RemoteSegmentArchiveEntry#getUuid()}}.
* Also gives a modest reduction in the index's steady-state memory footprint: 
the previous {{Map<UUID, RemoteSegmentArchiveEntry>}} (built via 
{{Map.ofEntries}}, which returns an immutable {{MapN}}) stores its entries in a 
single flat {{Object[]}} table sized to hold both keys and values, reusing the 
{{UUID}} each {{RemoteSegmentArchiveEntry}} already carries as the key, so no 
extra {{UUID}} or node/wrapper object is allocated per entry there either. 
{{SegmentIndex}}'s table only needs to hold the {{RemoteSegmentArchiveEntry}} 
reference itself, since the identifier is hashed on lookup rather than stored, 
so its array is roughly half the size of the old one.

  was:
{{AbstractRemoteSegmentArchiveReader#readSegment(long, long)}} and 
{{#containsSegment(long, long)}} are called once per segment reference and are 
on the hot path of online compaction. They currently look up a {{Map<UUID, 
RemoteSegmentArchiveEntry>}}, which requires allocating a new {{UUID}} object 
for every call just to use as a lookup key, plus paying for 
{{UUID.hashCode()}}/{{equals()}} through a generic {{HashMap}}.
* Add a small, package-private open-addressing map ({{SegmentIndex}}) keyed 
directly on the raw {{(msb, lsb)}} long pair, built once per archive open 
({{SegmentIndex.Builder}}, not on a hot path) and queried without any 
per-lookup allocation.
* {{AbstractRemoteSegmentArchiveReader}} is updated to use it instead of a 
{{UUID}}-keyed map. {{getSegmentUUIDs()}} (not on the hot path) still returns 
{{UUID}}s, built lazily from the index's entries by reusing each entry's 
existing {{RemoteSegmentArchiveEntry#getUuid()}}.
* Also reduces the index's steady-state memory footprint: {{SegmentIndex}} 
stores each {{RemoteSegmentArchiveEntry}} reference directly in a flat array, 
whereas the previous {{Map<UUID, RemoteSegmentArchiveEntry>}} additionally 
required one {{UUID}} object per entry (used purely as a map key) and one 
internal map-entry/node wrapper object per entry. For an archive with many 
thousands of segments, that's two extra object headers plus their fields per 
segment eliminated, on top of the per-lookup allocation removed from the hot 
path.


> Avoid UUID allocation and add O(1) index for in-archive segment lookup
> ----------------------------------------------------------------------
>
>                 Key: OAK-12417
>                 URL: https://issues.apache.org/jira/browse/OAK-12417
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>            Reporter: Nuno Santos
>            Priority: Major
>
> {{AbstractRemoteSegmentArchiveReader#readSegment(long, long)}} and 
> {{#containsSegment(long, long)}} are called once per segment reference and 
> are on the hot path of online compaction. They currently look up a 
> {{Map<UUID, RemoteSegmentArchiveEntry>}}, which requires allocating a new 
> {{UUID}} object for every call just to use as a lookup key, plus paying for 
> {{UUID.hashCode()}}/{{equals()}} through a generic {{HashMap}}.
> * Add a small, package-private open-addressing map ({{SegmentIndex}}) keyed 
> directly on the raw {{(msb, lsb)}} long pair, built once per archive open 
> ({{SegmentIndex.Builder}}, not on a hot path) and queried without any 
> per-lookup allocation.
> * {{AbstractRemoteSegmentArchiveReader}} is updated to use it instead of a 
> {{UUID}}-keyed map. {{getSegmentUUIDs()}} (not on the hot path) still returns 
> {{UUID}}s, built lazily from the index's entries by reusing each entry's 
> existing {{RemoteSegmentArchiveEntry#getUuid()}}.
> * Also gives a modest reduction in the index's steady-state memory footprint: 
> the previous {{Map<UUID, RemoteSegmentArchiveEntry>}} (built via 
> {{Map.ofEntries}}, which returns an immutable {{MapN}}) stores its entries in 
> a single flat {{Object[]}} table sized to hold both keys and values, reusing 
> the {{UUID}} each {{RemoteSegmentArchiveEntry}} already carries as the key, 
> so no extra {{UUID}} or node/wrapper object is allocated per entry there 
> either. {{SegmentIndex}}'s table only needs to hold the 
> {{RemoteSegmentArchiveEntry}} reference itself, since the identifier is 
> hashed on lookup rather than stored, so its array is roughly half the size of 
> the old one.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to