Skip to content

perf: uses single-draw entropy, hash slicing, and lazy imports - #75

Draft
wgordon17 wants to merge 3 commits into
mainfrom
refactor/hot-path-performance
Draft

wgordon17 wants to merge 3 commits into
mainfrom
refactor/hot-path-performance

Conversation

@wgordon17

@wgordon17 wgordon17 commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Replaces per-character random() draws with single-draw getrandbits(k) MSB fixed-point scaling (< 2^-64 relative bias per NIST SP 800-90A §B.5.1.1, immune to weak low bits) and narrows Cuid.generate()'s state.lock critical section (5.10x faster single-thread generate(), 5.54 µs vs 28.23 µs; 9.52x faster 4-thread shared create_id() and 15.19x faster 8-thread per-thread Cuid().generate() on Python 3.14t)
  • Encodes only the leading resolved_length + 1 base36 digits of 99- and 100-digit SHA3-512 digests via utils._create_hash_slice while preserving 100% output equivalence with utils.create_hash
  • Defers inspect and socket imports, switches SystemRandom import from secrets to random, and uses compile-time alphabet literals with local loop bindings (44.7% faster cold import cuid2, 4.86 ms vs 8.79 ms)

This branch has not been deployed

No deployments
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