Skip to content

Token.* methods and runtime codegen optimizations#12

Closed
aquapi wants to merge 3 commits into
sinclairzx81:mainfrom
aquapi:main
Closed

Token.* methods and runtime codegen optimizations#12
aquapi wants to merge 3 commits into
sinclairzx81:mainfrom
aquapi:main

Conversation

@aquapi
Copy link
Copy Markdown
Contributor

@aquapi aquapi commented Mar 22, 2026

Optimize Token.* methods and runtime code generator

@aquapi aquapi marked this pull request as ready for review March 22, 2026 09:03
@aquapi aquapi marked this pull request as draft March 22, 2026 09:03
@aquapi aquapi changed the title Micro-optimizations Token.* methods and runtime codegen optimizations Mar 22, 2026
- guard.ts
- TakeVariant(A, input) to Take([A], input)
Copy link
Copy Markdown
Owner

@sinclairzx81 sinclairzx81 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So, have had a look at the PR, and keen to try out these optimizations!

I have had to flag a few format related issues though. Mostly the intention here is to try keep the number of edits to an absolute minimum so that it's possible to focus on the optimizations only (the exact functional updates) and reduce the PR footprint to only significant edits (the format changes add a lot of noise to the PR)

In all though, I am keen to try these updates out! The replacement of the if logic over the IIFE closures for ternary expressions i expect could improve performance (so would be keen to test these with associated benchmarks). If extra performance can be attained, can probably consider establishing a consistent symmetric pattern to replace ternary ?: for if).

Good work! :)

Comment thread .vscode/settings.json Outdated
Comment thread src/token/internal/char.ts
Comment thread src/token/internal/char.ts
Comment thread src/token/internal/guard.ts
Comment thread src/token/internal/optional.ts
Comment thread src/token/until.ts
Comment thread src/token/until_1.ts
Comment thread src/token/internal/trim.ts Outdated
Comment thread src/token/internal/trim.ts
Comment thread .zed/settings.json Outdated
@aquapi
Copy link
Copy Markdown
Contributor Author

aquapi commented Mar 24, 2026

@sinclairzx81 maybe I should do the runtime codegen in a different PR

@sinclairzx81 sinclairzx81 mentioned this pull request Mar 27, 2026
@aquapi aquapi marked this pull request as ready for review March 27, 2026 12:19
@sinclairzx81
Copy link
Copy Markdown
Owner

@aquapi Thanks so much for this!

This was an awesome bit of research into ParseBox optimization. Upstream testing showed 2-3x performance for TypeBox Script Parse which is amazing!

I have selected the parts of this PR I can incorporate for now, those being:

  • IsResult - Remove IsArray Check
  • Take(...) - Use inline for-loop over type symmetric ternary logic (very good optimization this one!)

And added you as a co-contributor for 0.11.3 via PR #14.

This is amazing work! Thanks for taking the time to review! Will close this PR out via #14
All the best!
S

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