Skip to content

feat: add batch ID generation - #44

Closed
aalu-love wants to merge 5 commits into
suhailopensource:mainfrom
aalu-love:feat/batch-id-generation
Closed

aalu-love wants to merge 5 commits into
suhailopensource:mainfrom
aalu-love:feat/batch-id-generation

Conversation

@aalu-love

Copy link
Copy Markdown

Summary

  • Add .many(prefix, count) for standard and sortable ID generators.
  • Add batch-size validation and safe chunking for large random-byte requests.
  • Add tests for batch generation, count validation, and sortable ordering.
  • Add a benchmark comparing individual and batch generation.
  • Update the changelog.

Benchmark

Generating 20,000 standard IDs in local measurements:

  • Individual generation: 60.37 ms median
  • Batch generation: 13.69 ms median
  • Observed speedup: 4.41×
  • Time reduction: 77.3%

Results may vary depending on the runtime and machine.

Checklist

  • npm run verify passes.
  • Tests cover standard batch generation.
  • Tests cover sortable batch ordering.
  • Invalid batch counts are rejected.
  • Large random-byte requests are safely chunked.
  • Existing IdGenerator function compatibility is preserved.
  • Changelog is updated.
  • Benchmark results are included.

Note

Sortable batch generation currently calls the single-ID generator repeatedly. It preserves monotonic ordering but does not yet batch random-byte generation for sortable IDs.

@aalu-love
aalu-love marked this pull request as ready for review October 10, 2026 15:18
@aalu-love aalu-love changed the title Feat/batch id generation feat: add batch ID generation Oct 10, 2026
@suhailopensource

Copy link
Copy Markdown
Owner

Hi @aalu-love, thank you so much for this PR, and sorry for the bad news. I checked it closely, and the core of it is solid:

  • BatchIdGenerator is the right shape, and IdGenerator is unchanged.
  • Big batches stay under the 65,536-byte getRandomValues limit on the CJS and Node ESM builds, and in Bun and Deno.
  • Sampling stays unbiased, and sortable batches stay strictly increasing, even when they spill into the next millisecond.
  • The single-ID path is byte-for-byte the same as main.
  • You were upfront that sortable batches aren't faster. I appreciated that.

Two PRs ended up implementing #36: this one and #45. Only one can merge, because they change the same lines. Yours came first, so this wasn't an easy call. I'm going with #45 because it's much closer to ready: it passes npm run verify, its types work, and it has the tests the issue asked for. This one would need several fixes first:

  • npm run verify fails. Prettier flags 9 files, and coverage drops to 97.67% lines / 96.49% branches (the thresholds are 99% / 97%).
  • id.many() and sortableId.many() don't compile in TypeScript. The exported id and sortableId are still typed IdGenerator, so TypeScript says Property 'many' does not exist on type 'IdGenerator'. id.many("user", 1000) is the main example in the issue.
  • Some tests the issue asks for are missing: the type-level IdGenerator test, sortable count validation, and the sortable overflow case.

So I'm closing this one. It's not about the effort or the idea. The core logic here is good.

Part of the mix-up is on me. The repo has no rule for claiming issues, and this PR didn't link #36, so the issue page didn't show that anyone was working on it. I'll add a short note to CONTRIBUTING.md about claiming issues. Two tips for next time:

  • Put Closes #<number> in the PR description. It links the PR to the issue, so others can see the issue is taken.
  • Run npm run verify before ticking that box in the checklist. It runs the same checks as CI.

I'd love to have you back. #38 (prefid-ai, a typed ID generator for the Vercel AI SDK) is open, marked help wanted, and nobody has picked it up. If it interests you, leave a comment there and we can work out the scope together. Thanks again!

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.

2 participants