Skip to content

refactor(decode): extract shared FastLanes unpack schedule in BitpackedEncodingDecoder#140

Merged
dfa1 merged 2 commits into
mainfrom
refactor/bitpacked-unpack-schedule
Jun 23, 2026
Merged

refactor(decode): extract shared FastLanes unpack schedule in BitpackedEncodingDecoder#140
dfa1 merged 2 commits into
mainfrom
refactor/bitpacked-unpack-schedule

Conversation

@dfa1

@dfa1 dfa1 commented Jun 23, 2026

Copy link
Copy Markdown
Owner

What

The four unpackLoop8/16/32/64 methods each rebuilt an identical per-row schedule (shifts, remaining/current bits, lo/hi masks, current/next word byte bases, transposed output offsets), differing only by typeBits and element width. Sonar flagged the four ~24-line setup blocks as duplication.

Hoisted that cold, run-once precompute into an UnpackSchedule record built by schedule(typeBits, bitWidth), which derives lanes = 1024/typeBits and elemBytes = typeBits/8 internally. Each loop now calls schedule(N, bitWidth) and aliases the arrays. ~80 duplicated lines collapse to one method.

What is deliberately NOT collapsed

The per-element inner unpack loops stay specialised per width. A generic ValueLayout/accessor would stop C2 from constant-folding the typed access and block superword vectorisation (hot-loop rule). Only the cold, run-once setup is shared — no hot-path change.

Verification

  • 120 round-trip decode tests (all widths + patches) — pass
  • 107 encoder tests — pass
  • reactor build + build-enforced javadoc (new record @params) — clean

🤖 Generated with Claude Code

dfa1 and others added 2 commits June 23, 2026 08:12
The arena parameter is contractual: this base method implements
Array#materialize(SegmentAllocator) for the leaf Materialized* classes,
which implement the sealed Array interface directly. Sonar cannot see the
override because the base class is not itself declared to implement Array,
so it flagged arena as an unused parameter. The parameter must stay to
satisfy the interface; suppress with an explanatory reason instead.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…edEncodingDecoder

The four unpackLoop8/16/32/64 methods each rebuilt an identical per-row
schedule (shifts, remaining/current bits, lo/hi masks, current/next word byte
bases, transposed output offsets), differing only by typeBits and element
width. Sonar flagged the four ~24-line setup blocks as duplication.

Hoist that cold, run-once precompute into an UnpackSchedule record built by
schedule(typeBits, bitWidth), which derives lanes (1024/typeBits) and
elemBytes (typeBits/8) internally. Each loop now calls schedule(N, bitWidth)
and aliases the arrays.

The per-element inner unpack loops stay specialised per width on purpose: a
generic ValueLayout/accessor would stop C2 from constant-folding the typed
access and block superword vectorisation (hot-loop rule). Only the cold setup
is shared, so there is no hot-path change.

Verified: 120 round-trip decode tests (all widths + patches) and 107 encoder
tests pass; reactor build + build-enforced javadoc clean.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dfa1 dfa1 merged commit e683a63 into main Jun 23, 2026
6 checks passed
@dfa1 dfa1 deleted the refactor/bitpacked-unpack-schedule branch June 23, 2026 06:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant