Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Performance improvements #2171

Merged
merged 17 commits into from Aug 18, 2020
Merged

Performance improvements #2171

merged 17 commits into from Aug 18, 2020

Commits on Aug 18, 2020

  1. add perf utils

    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    4b15b90 View commit details
    Browse the repository at this point in the history
  2. bail out of the applyComplexClasses when it is not needed

    There is no need in re-compiling tailwind or building expensive lookupt
    tables when it turns out that we don't even need it.
    
    We have a small overhead by walking the tree to check if `@apply`
    exists. However this outweighs the slowness of re-generating tailwind +
    expensive lookup tables.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    8c7fb84 View commit details
    Browse the repository at this point in the history
  3. re-use classNameParser

    We were re-creating the classNameParser inside the loop. Since that code
    is all pretty pure we can hoist it so that we don't have to recreate
    that parser all the time.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    aa7ae6a View commit details
    Browse the repository at this point in the history
  4. remove unused containsApply check

    Currently we will walk the tree for every single rule to see if an
    `@apply` exists somewhere in that tree. However we don't use the
    `containsApply` anymore so this is a quick win!
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    5564e0b View commit details
    Browse the repository at this point in the history
  5. make the cloning of the rule in the lookup table lazy

    We create a big lookup table so that we can lookup the nodes by its
    utilityName. This is used inside the recursive `@apply` code.
    
    This big lookup table will clone every single rule and put it in,
    however we don't need to clone everything! We are only interested in the
    rules that have been actually applied.
    
    This way we make the cloning of the rule lazy and only when we use this
    exact rule.
    
    There is an additional performace "issue" though: When we read the same
    rule multiple times, it will clone every time you read from that object.
    We could add additional memoization stuff, but so far it doesn't seem to
    be the bottleneck. Therefore I've added a perf todo just to leave a mark
    when this becomes the bottleneck.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    f2e3e22 View commit details
    Browse the repository at this point in the history
  6. switch to a do {} while ()

    We alreayd know that we have an `@apply` otherwise we would not have
    called that function in the first place. Moving to a `do {} while ()`
    allows us to skip 1 call to `hasAtRule(css, 'apply')`. Which is nice
    because that skips a possible full traversal.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    88888fd View commit details
    Browse the repository at this point in the history
  7. remove the reversed orderedUtilityMap

    We don't require this reversed map since we can already sort by the
    index on the node directly. Therefore this can be dropped.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    e39fd6f View commit details
    Browse the repository at this point in the history
  8. Copy the full SHA
    309b8e5 View commit details
    Browse the repository at this point in the history
  9. hoist the selector parser

    No need to re-create the selector parser in the loop for each selector.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    78df100 View commit details
    Browse the repository at this point in the history
  10. improvement cloning of the parent node

    We used to clone the full tree and then remove all the children, this
    was a bit too slow so therefore we will now create a new tree based on
    the old information.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    00f4427 View commit details
    Browse the repository at this point in the history
  11. introduce a useMemo utility

    Naming is hard so I took this name from the React hook 😎
    
    Also use this useMemoy utility to make sure that the extractUtilityNames
    is cached. There is no need to re-compute the utility names all the
    time.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    0631851 View commit details
    Browse the repository at this point in the history
  12. cache buildSelectorVariant

    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    fab4d7b View commit details
    Browse the repository at this point in the history
  13. hoist selectorParser setup code

    No need to re-create the selectorParser in every call.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    8ae2a32 View commit details
    Browse the repository at this point in the history
  14. Copy the full SHA
    5260c71 View commit details
    Browse the repository at this point in the history
  15. cache clone rule

    Otherwise every time we read this value it will be re-cloned
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    e417da2 View commit details
    Browse the repository at this point in the history
  16. use append instead of prepend

    Same idea, but prepend will internally reverse all nodes.
    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    fe70c89 View commit details
    Browse the repository at this point in the history
  17. cache className resolve

    RobinMalfait authored and adamwathan committed Aug 18, 2020
    Copy the full SHA
    33ee646 View commit details
    Browse the repository at this point in the history