Skip to content

hash niche optimisation#322

Merged
Smattr merged 3 commits into
mainfrom
smattr/fe523439-9abf-44d4-8c11-cfd5c07d2c71
May 9, 2026
Merged

hash niche optimisation#322
Smattr merged 3 commits into
mainfrom
smattr/fe523439-9abf-44d4-8c11-cfd5c07d2c71

Conversation

@Smattr
Copy link
Copy Markdown
Owner

@Smattr Smattr commented May 9, 2026

No description provided.

Smattr added 3 commits May 3, 2026 17:56
The pointers saved to the seen state set typically have some unused
bits. For example, on x86-64 they are 8-byte aligned, making the bottom
3 bits known-zero. With x86-64 Linux 4-level paging, the upper 16 bits
are also known-zero.

This change leverages the upper known-zero bits to store a state
discrimination hint in the form of part of the state’s hash:

   63            48 47                                          3 2 0
   ▼              ▼ ▼                                           ▼ ▼ ▼
  ┌────────────────┬─────────────────────────────────────────────┬───┐
  └────────────────┴─────────────────────────────────────────────┴───┘
     hash[63:48]                  state pointer                    0

The point of this is that state equality comparisons can be optimised by
first checking these upper bits. If two state slot’s upper bits are not
equal, we know the pointed to states differ. This is a slight runtime
performance improvement:

  ┌─────────────────────────┬────────┬────────┐
  │                         │ before │  after │
  ├─────────────────────────┼────────┼────────┤
  │ misc/pending-queue.m    │  8m02s │  7m45s │
  │ misc/pending-queue-4k.m │  8m01s │  7m59s │
  └─────────────────────────┴────────┴────────┘

Note that the discussion above implies we are still leaving some
performance on the table. The low 3 bits are known-zero and could also
be repurposed in future.
@Smattr Smattr force-pushed the smattr/fe523439-9abf-44d4-8c11-cfd5c07d2c71 branch from cfd2e71 to 7525def Compare May 9, 2026 19:39
@Smattr Smattr merged commit faac216 into main May 9, 2026
22 checks passed
@Smattr Smattr deleted the smattr/fe523439-9abf-44d4-8c11-cfd5c07d2c71 branch May 9, 2026 21:43
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