Skip to content

Conversation

@bschlenk
Copy link
Contributor

Changes

Hi Drew! This PR removes all uses of isTokenMatch, instead calling wcmatch outside of loops and then using the returned function inside loops. I found that this dropped Figma's token build times from 35s down to 7s.

I left isTokenMatch since it's exported from @terrazzo/token-tools, but marked it as @deprecated. Not sure if that's the right move here, but given that it can lead to a big perf hit if used too much, I think it could be removed in the future.

Let me know if you think the wcmatch(patterns) call should be wrapped in a helper in token-tools, I could see it handling null inputs and returning a dummy function so callers don't have to handle that themselves.


I was profiling tz build and the transform function from wildcard-match was dominating the profile. I think it was one of those hidden quadratic complexity things because calling wcmatch(patterns) does a bunch of work to build up an efficient regex, but that work was being done repeatedly on the same patterns when it could be done once.

Screenshot 2025-06-23 at 12 23 06 PM

CPU-20250621T224815.cpuprofile

How to Review

This is mostly a find and replace of the isTokenMatch function, so it should be easy to review. The wcmatch function is called in the highest scope possible where the matching patterns can be compiled once by wcmatch, and then reused within loops.

@changeset-bot
Copy link

changeset-bot bot commented Jun 23, 2025

🦋 Changeset detected

Latest commit: 825b427

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@terrazzo/cli Minor
@terrazzo/parser Minor
@terrazzo/plugin-css Major
@terrazzo/plugin-js Major
@terrazzo/plugin-sass Major
@terrazzo/plugin-tailwind Major
@terrazzo/token-tools Minor
@terrazzo/plugin-swift Major
@terrazzo/plugin-vanilla-extract Major
@terrazzo/token-lab Patch
@terrazzo/use-color Patch
@terrazzo/react-color-picker Patch
@terrazzo/tiles Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@drwpow
Copy link
Collaborator

drwpow commented Jun 23, 2025

Nice! I’d be OK with just removing isTokenMatch() in a minor (breaking) change. If you could get the CI checks passing, and add a changeset (see comment), I’d be happy to merge & release 🙏

@bschlenk
Copy link
Contributor Author

I'm not sure why test-windows is failing, it doesn't seem related to my changes 🤔 it says it can't find the terrazzo.config.js file during the test

@drwpow
Copy link
Collaborator

drwpow commented Jun 23, 2025

Oh I can take a look. Not sure either, but yeah probably unrelated. Thanks!

@drwpow drwpow merged commit 9b80fd4 into terrazzoapp:main Jun 23, 2025
4 of 5 checks passed
@github-actions github-actions bot mentioned this pull request Jun 23, 2025
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