Skip to content

JS Map.bit reconstructs the key prefix just to return the unchanged key #1702

Closed as not planned

Description

@oxura

Map.bit walks to a requested key bit and reconstructs the traversed String prefix on the way back. The returned key is unchanged, so that reconstruction isn't needed by the JS host representation.

Repro wrapper:

import Base
def bit(key: String, position: Nat) -> String & Bool:
  Map.bit(key, position)

With key = 'x'.repeat(256) + 'q' and position 8480, 1,000 exported calls per round: nine warmed alternating rounds measured 27.712 ms before and 2.444 ms after. The returned key was checked on every call and both boolean sums were 1,000. Linux x64/Bun 1.3.13, existing #1682 head 0b82c20 versus the patch.

The new walk returns the original key and preserves the 33-bit encoding: one presence bit, then 32 U32 bits most-significant first. Oracle checks cover all bit positions in mixed Unicode/NUL keys, EOF and wide Nat positions; the emitted Bun/native C fixture checks packed U32 Chars too. No change to the Base theory or the C path.

Patch: oxura@aa331dfd
Included in existing PR #1682.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions