blakeembrey / free-style

Make CSS easier and more maintainable by using JavaScript
MIT License
707 stars 29 forks source link

[V1] Rewrite for performance of both size and speed #6

Closed blakeembrey closed 8 years ago

blakeembrey commented 9 years ago

A lot of the old architecture has been removed and simplified. Only strings are now cached (no duplication of object and string) and exposed to end users (E.g. Style.registerStyle() outputs a string instance of instance). Every instance can container other instances, and all have a consistent hash to merge duplicate styles/@-rules/selectors into each other. Basically:

FreeStyle -> AtRule -> AtRule | (Style -> Selector)
namuol commented 9 years ago

While we're on the subject of performance and non-backwards-compatible changes, it might be worth trying out this alternative hashing function.

Here's a quick jsPerf test; it performs about 2x faster in my browser -- might be an easy win!

blakeembrey commented 9 years ago

@namuol Thanks for sharing the algorithm. I'll do some test cases for speed and uniqueness, but yeah, that's definitely the biggest feature/bottleneck.

Edit: As in, it's the core of all the functionality so kind of important, not that it's the slowest feature.