You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@polaris.apache.org by "iting0321 (via GitHub)" <gi...@apache.org> on 2026/06/23 12:46:32 UTC

[PR] Optimize privilege set BitSet byte-to-long conversion [polaris]

iting0321 opened a new pull request, #4869:
URL: https://github.com/apache/polaris/pull/4869

   <!--
   ๐Ÿ“ Describe what changes you're proposing, especially breaking or user-facing changes. 
   ๐Ÿ“– See https://github.com/apache/polaris/blob/main/CONTRIBUTING.md for more.
   -->
   ## Summary 
   Implement the existing `BitSet.valueOf(byte[])` optimization TODO `// TODO valueOf(byte[]) is way more expensive than valueOf(long[]) `  in `PrivilegeSetImpl`.
   
   `BitSet.valueOf(long[])` is cheaper than `BitSet.valueOf(byte[])`, so this change adds a small little-endian byte-to-long conversion helper and uses it in the `add` and `remove` paths.
   ## Change
     - Add `PrivilegeSetImpl.toLongArray(byte[])`.
     - Use `BitSet.valueOf(long[])` when merging or subtracting privilege sets.
     - Add coverage to verify the converted `long[]` produces the same `BitSet` representation as the original byte array, including empty, partial, full 8-byte, and multi-long inputs.
   
   #### Explain of toLongArray(byte[]) 
     1. new long[(bytes.length + 7) / 8] allocates enough longs for all bytes, 8 bytes per long.
     2. bytes[i] & 0xFF treats each byte as unsigned, avoiding sign extension.
     3. i / Long.BYTES picks which long the byte belongs to.
     4. (i % Long.BYTES) * Byte.SIZE picks the byteโ€™s bit offset inside that long.
     5. |= adds that byte into the long without overwriting earlier bytes.
   
   So bytes 0..7 become longs[0], bytes 8..15 become longs[1], etc., preserving BitSetโ€™s little-endian layout.
   
   ## Test
   - Add test coverage in `persistence/nosql/authz/impl/src/test/java/org/apache/polaris/persistence/nosql/authz/impl/TestPrivilegeSetImpl.java`
   
   ## Checklist
   - [x] ๐Ÿ›ก๏ธ Don't disclose security issues! (contact security@apache.org)
   - [x] ๐Ÿ”— Clearly explained why the changes are needed, or linked related issues: Fixes #
   - [x] ๐Ÿงช Added/updated tests with good coverage, or manually tested (and explained how)
   - [x] ๐Ÿ’ก Added comments for complex logic
   - [ ] ๐Ÿงพ Updated `CHANGELOG.md` (if needed)
   - [ ] ๐Ÿ“š Updated documentation in `site/content/in-dev/unreleased` (if needed)
   


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Optimize privilege set BitSet byte-to-long conversion [polaris]

Posted by "snazy (via GitHub)" <gi...@apache.org>.
snazy merged PR #4869:
URL: https://github.com/apache/polaris/pull/4869


-- 
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: issues-unsubscribe@polaris.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org