Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #, if available:
There are some performance related issues with having loads of references (especially chained ones) due to always having to traverse the entire tokens object to find a reference, and for each member of the chain too.
This PR is the second of a series of 3 PRs aimed at tackling this problem. The first was to create a utility to convert a tokens object to a Map structure, which makes it a lot cheaper than Array.find() or Object traversal to access the referenced tokens, while still making it convenient to iterate/loop over.
This PR completely refactors the reference resolver and token transformer lifecycle to use the Map() instead of the Object. There is still a small bit of object traversal happening for the resolver, but only at the level of the token's value property which could be a (nested) object. Besides that, it uses direct Map.get() to find a reference which is very fast.
The third PR is still to be started, which will look into caching reference lookups so that if multiple references end up resolving to the same token (e.g. because of chained refs with the last item being the same one), preventing the same work from having to be done more than once. I suspect the performance gains of this PR to be more of a bonus compared to the previous 2, and only significant for tokensets with loads of deep chained refs.
One thing to note is that this PR is a breaking change, which would mean a new major version of Style Dictionary, for 2 main reasons:
.value
(or.$value
in DTCG) suffix support in token references, this is not really aligned with the DTCG spec and imo is a feature no one really needs or should be using. It's technically possible to keep the backward compatibility for it so let's discuss whether we want to remove it fully or merely stop using it in our docs/examples.TODOs:
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.