mootools / mootools-core

MooTools Core Repository
https://mootools.net
2.65k stars 511 forks source link

Performance of setStyle #2679

Open oallouch opened 9 years ago

oallouch commented 9 years ago

Hi everyone, In modern web (or mobile) applications, setStyle can be called millions of times. It's, for me, the most crucial code for good lower level performance. So, optimization ideas for the Element.setStyle function: . remove the camelCase(). I've already done it in my version. Try it ! It's great :) . remove the Math.round around 'val'. With retina screens, sub-pixels become real pixels . (Element.Styles[property] || '@').split(' ') should be cached. Instead of Strings, Element.Styles values should be Arrays . if the split array has a length of 1, we don't have to do a "Array.from(value)"

What do you think of it ?

Thx,

Olivier Allouch http://www.illicotravel.com

--- Want to back this issue? **[Post a bounty on it!](https://www.bountysource.com/issues/6506644-performance-of-setstyle?utm_campaign=plugin&utm_content=tracker%2F22067&utm_medium=issues&utm_source=github)** We accept bounties via [Bountysource](https://www.bountysource.com/?utm_campaign=plugin&utm_content=tracker%2F22067&utm_medium=issues&utm_source=github).
SergioCrisostomo commented 9 years ago

@oallouch nice input! We will be dropping some old browsers soon and that will make possible some nice refactoring. If you want to take part on that would be great. I can ping you here.

oallouch commented 9 years ago

I don't have plenty of time (3 parallel projects), but always for mootools !

DimitarChristoff commented 9 years ago

to be honest you don't need to maintain your own version of mootools for this - just add Element.prototype.css = function(key, value) { .. your faster one } and use it like jQuery. If you change styles all the time you are probably animating - and if performance is your concern, look at velocity.js as it is cleaner and perf-centric style changes / tweens

oallouch commented 9 years ago

It's the camelCase that hurts most, but, you're right, it comes from an age when we didn't have css animations. Thx for the velocity tip. Looks great.