-
Notifications
You must be signed in to change notification settings - Fork 73
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: EQCSS timers, throttle #85
Comments
P.S. Ideally there'd be a high performance version of the lib without any timers, throttling, or any other delays. (And perhaps it would also make the lib faster to reduce/avoid DOM writes such as eg these: from one element: Just ideas 😀 In any case I hope that the perf issue I described in the first message can be resolved somehow. |
Nice demos! I see the difference you're talking about between the two, and I can understand wanting to circumvent the throttle. I'm not sure we'll take it out of the main EQCSS library but feel free to make an alternate build that lacks it. Originally EQCSS didn't have a throttle, but then at some point Firefox's performance degraded to a point where adding a throttle was a necessity. 2016 was a long time ago you might say, maybe with the new Firefox Quantum we can finally get the performance boost we need to remove the throttle? Not quite, it appears the new version of Firefox is worse for event-driven styling:
They consider fixing one of these problems a low priority:
Lol! So I guess I'm either a) not a real web developer, or b) my sites aren't real websites haha. Hopefully they find a way to fix their browser. So the throttle should stay in the main EQCSS.js library unfortunately, and as buttery smooth and nice as it is calling Now, separately for the idea of a 'high-performance EQCSS' I have a few ideas:
I've done both of these, so I'll let you measure the results or see what you might like to use. For one of our users who was only using the The second alternative is something I started last month, I've been experimenting with 'event-driven virtual stylesheets' outside of EQCSS using a pattern I call 'JS-in-CSS', and so I rewrote the features and functionality of EQCSS as a JS-in-CSS plugin that's much smaller than EQCSS.js. It doesn't parse a custom CSS-like syntax, but you're able to use JavaScript to call it and the inner stylesheet format is the same as EQCSS: https://gist.github.com/tomhodgins/fa127a2d98ff8d4dcb936bdd007da0b0 One downside is that JS is only aware of pixels for breakpoints, where with EQCSS we tried to parse any CSS units for the breakpoints, but perhaps that's where performance can be improved. The following two examples are equivalent, but I bet the EQCSS JS-in-CSS version beats the EQCSS.js regular version for performance: EQCSS Demo <input>
<style>
@element input and (min-characters: 5) {
:self {
background: lime;
}
}
</style>
<script src=http://elementqueries.com/EQCSS.js></script> EQCSS-in-JS helper function <input>
<style>
${eqcss('input', {minCharacters: 5}, `
:self {
background: lime;
}
`)}
</style>
<script src=https://rawgit.com/tomhodgins/fa127a2d98ff8d4dcb936bdd007da0b0/raw/34976ac3615407294b07879741721a6a254d6569/eqcss-mixin.js></script>
<script src=https://staticasset.s3.amazonaws.com/jic.js></script> Even though they function nearly equivalently, and even though the second example looks a little strange, every character of the second demo is either standard CSS or standard JS too, so that's an added advantage. You get the same result as if you populated a eqcss('input', {minCharacters: 5}, ':self { background: lime; }') Hopefully that helps point you in the right direction. Having EQCSS.js working in IE8 and up makes me not want to change it too drastically, but gives me the freedom to experiment a little with other ideas that may not have as broad support needs :D |
Thanks for your reply! (Also see my comments on the bug pages you linked.) Perhaps you could offer an option for disabling all throttling?
Throttling would stay in the lib, and it would still be the default, but lib users (including me) could disable it by adding just one line. |
Adding this line resolved all my woes:
Now I have this in total:
At https://tobireif.com/demos/grid/ all's good now 😁 Feel free to use any of this for the lib & docs. |
Hi Tobi!
To me it reads as:
If the throttle was necessary because EQCSS-powered sites in the wild became broken as Firefox updated, making it easy for people to build in ways that will be broken in Firefox seems irresponsible :/ I'm not sure Firefox performance is improving in this area, so the throttle may become more necessary as time goes on, rather than less necessary. Originally it wasn't required at all. I'm glad you've found a workaround—that's similar to what I'd do to workaround the throttle as well, but I don't think bypassing the throttle would be a good option to offer to people who don't know how to bypass it themselves, because they are likely to enable it without testing their use-cases thoroughly in firefox to make sure it's okay—if it appears faster and smoother in every browser (apart from Firefox) without a throttle, I imagine most people who notice that would disable it given the choice. I do think the EQCSS-in-JS function might be usable in Firefox without a throttle as-is simply because it's smaller and can run faster. Compare these two demos, one is EQCSS and one is EQCSS-in-JS. If you're looking for better performance than EQCSS.js I'd recommend moving that direction, rather than trying to optimize EQCSS.js:
I think this would be a better way to gain performance and avoid a throttle at the same time :D |
Again: You could add the option with a specific warning (eg does it only affect scroll-performance?), or don't add it - it's up to you.
I enjoy writing the element queries in one place with the other CSS, and the code I added is an effective way to avoid throttling and to get great perf 😀 |
Hi, I'm trying to wrap my head around different element query solutions and their performance. I stumbled upon css-element-queries and their approach appears to avoid event listeners on "resize" as you do. Am I missing something, or is their approach much simpler than the one this library here offers? I know it's not specifically related to the throttling issue you're discussing here, but I'm trying to understand why throttling is needed in the first place, when the desired goal - as far as I can tell - could be reached without it. Thank you. EDIT: OK, after heaving read this article I start to believe that ResizeObserver is the future-proof way to go. |
@mmzoo EQCSS was designed to be dropped into any page and hopefully Just Work™, and a throttle wasn't required originally, but at one point in time Firefox changed something about scroll events and unless EQCSS throttled the number of computations, existing websites were totally frozen and couldn't even be scrolled. So it's a historical workaround for a bad browser at one point in time. You're right that ResizeObserver shows a lot of promise for providing the knowledge for when an element query should reprocess if it's a width or height-based condition like These days I find myself applying element queries with much smaller abstractions, like jsincss-element-query which isn't hooked up to any Observers or listeners - so you're free to integrate it into your code and hook up the listeners that should drive its recalculation! The most recent thing I've been doing is parsing valid custom CSS like this into the JS runtime it needs to run what it found automatically - so you write CSS and deliver self-contained JS that runs what you wrote. |
Hi Tom!
Please load the Grid demo
https://tobireif.com/demos/grid/
and set the window width to eg ~900px.
Click on "Layout 2", note the delay in the layout update.
Click on "Layout 1", note the delay in the layout update.
I did a perf profile, the perf hits involve EQCSS timers and EQCSS throttling.
I already tried to circumvent the throttling.
I hope you can offer an EQCSS option for disabling all delays, timers, throttling, etc.
Any tips in the meantime?
Thanks for EQCSS!
The text was updated successfully, but these errors were encountered: