Skip to content

perf: implement non-mutating fast-path for unmaskTag and update docum…#4

Merged
scrrlt merged 1 commit into
mainfrom
perf/unmask-tag-fast-path
Mar 28, 2026
Merged

perf: implement non-mutating fast-path for unmaskTag and update docum…#4
scrrlt merged 1 commit into
mainfrom
perf/unmask-tag-fast-path

Conversation

@scrrlt

@scrrlt scrrlt commented Mar 28, 2026

Copy link
Copy Markdown
Owner

enhances both the documentation and implementation of the safe-tag library, focusing on improving performance, clarity, and benchmarking. changes include expanding the unmaskTag function to use a fast, non-mutating path for common built-in types, updating the documentation to clarify performance and usage, and refactoring the benchmarking script for better extensibility and coverage.

Enhancements to unmaskTag and Type Detection:

  • Added a fast, non-mutating detection path for common built-in types (Array, Date, RegExp, Map, Set, Promise, Function, Error) in unmaskTag, which avoids V8 de-optimization when possible. This uses the new internal getInnateTag helper. [1] [2]

  • Updated README.md to clarify the performance characteristics, behavior, and recommended usage of safeTag and unmaskTag, including details about the new fast-path and when to use advanced unmasking.

Benchmarking and Testing:

  • Refactored bench/index.js to:
    • Import and benchmark all tag variants (safeTag, unmaskTag, fastTag, ultraFastTag, cachedTag).
    • Use a reusable runBench function for cleaner, more extensible benchmarks.
    • Add benchmarks for the new tag variants and improve output formatting for better readability.

Summary by CodeRabbit

Release Notes

  • Performance

    • unmaskTag() now features a fast, non-mutating path for common built-in types, improving performance for typical detection scenarios.
  • Documentation

    • Updated API docs emphasizing safeTag() performance suitability for most use cases and clarified unmaskTag() guidance for detecting spoofed tags.
  • Type Safety

    • Improved type signatures for enhanced type checking accuracy.

@scrrlt
scrrlt merged commit 5189c0e into main Mar 28, 2026
0 of 2 checks passed
@scrrlt
scrrlt deleted the perf/unmask-tag-fast-path branch March 28, 2026 09:36
@coderabbitai

coderabbitai Bot commented Mar 28, 2026

Copy link
Copy Markdown

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 76988f66-33a0-4c9b-b7f7-646cae06247d

📥 Commits

Reviewing files that changed from the base of the PR and between 2c61bc5 and 7d6a4f4.

📒 Files selected for processing (4)
  • README.md
  • bench/index.js
  • src/fast.ts
  • src/index.ts

📝 Walkthrough

Walkthrough

Updated documentation for tag functions emphasizing performance characteristics. Refactored benchmark suite to test additional tag implementations. Improved type safety in ultraFastTag. Added fast-path optimization to unmaskTag via new internal helper for common built-ins.

Changes

Cohort / File(s) Summary
Documentation & Benchmarks
README.md, bench/index.js
Updated API documentation for safeTag and unmaskTag with performance guidance and use-case recommendations. Refactored benchmark suite with new runBench helper function to consistently test unmaskTag, fastTag, ultraFastTag, and cachedTag implementations.
Type Safety & Optimization
src/fast.ts, src/index.ts
Changed ultraFastTag type signature to accept unknown with explicit object cast. Added internal getInnateTag helper providing fast detection for common built-ins; integrated as optimized fast-path in unmaskTag with fallback to descriptor-unmasking and safeTag logic.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 With carrots bright and code so clean,
Fast paths carved through type routines,
Built-ins tagged with nimble grace,
Benchmarks race across the place!
Speedy tags, docs shining true,
TypeScript better, tested through! 🚀

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch perf/unmask-tag-fast-path

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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