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

  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}} and 
{{RemoteSegmentArchiveEntry}} are updated to use it instead of a {{UUID}}-keyed 
map; {{RemoteSegmentArchiveEntry#getUuid()}} (only used for that map key) is 
removed since it is no longer needed. {{getSegmentUUIDs()}} (not on the hot 
path) still returns {{UUID}}s, built lazily from the index.

Same "latest position wins" semantics are preserved when multiple blobs share 
the same segment identifier (e.g. after a retry).


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



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

Reply via email to