🏎️ feat: expose calculateForAST method#23
Conversation
|
Apologies for the delay but only now I took a good look into this PR. One thing I’m wondering is why |
|
~~The existing function already returned a single object, so I simply renamed it and exported it. It does make sense to me however to keep this method as small as possible, because it's easy to integrate and mock for testing.~~ edit: interpreted your question incorrectly For my use case I generate sometimes over 10,000 Specificity instances, each with a small enough footprint. Separating instantiating the |
|
My css-analyzer package has benchmarks enabled in CI and running it with the changes from this MR makes the analyzer 25-50% faster! projectwallace/css-analyzer#423 (comment) (I don't necessarily trust the benchmarks blindly and ~50% is probably waaaay too much, but I'm very confident that it's faster because it's making a lot fewer function calls and memory allocations) |
|
I did some local performance testing:
(This uses an unmodified package, all invocations return one These are the results: What is interesting is that the simple check As for the name, what about As for changing the return format (see https://github.com/bramus/specificity/pull/23/files#diff-b4fecae0a093d01e2d48a4410d338901e0e6bf09a6ef3b2a91c4dcf34b2cd61dR184), I would not do that as the package is meant to return I see no significant impact when I re-run all benchmarks when the functions return a simple object instead of a (Yes there is a difference, but I don’t see a huge impact) |
|
Excellent, excellent research! Shall I update the PR with these proposed changes? It'll solve my use case so I'm in favour and I'm happy to spend some more time on this if you want. 🙌 |
|
Please do. Afterwards I can commit the benchmarks too and then prepare a new release :) (And apologies for the delay, should have looked into this much much sooner) |
be1f89d to
57f6585
Compare
calculateSelectorNodecalculateForAST method
|
calculateForAST methodcalculateForAST method
|
Thanks for getting this across the finish line! |
closes #17
calculateSelectorNodenext to the existingcalculatefunctionSpecificity.calculateSelectorNode(selector: string)+ testscalculateSelectorNodedoes not need to referenceSpecificityeach time/test/standaloneis implemented correcty. I suspect the existing tests forcalculatedon't actually test it's implementation so I did mine a little different than the existing tests. Please double-check my work 😅. Also opened Question: are standalone tests correct? #24 for further discussion.