Performance Differences Between Color Declarations

Performance differences between color declarations?

If we assume a modern browser making full use of the GPU then the internal color representation will be RGB floats. Ignoring the color name - which is probably just a map to hex anyway - I think that hex and channels will be the fastest. HSB will undoubtedly be the slowest, as the conversion from HSB to RGB does require some work - about 50 lines of C code.

However, I think that for the purpose of CSS, this is a completely irrelevant question. Even for HSB to RGB the amount of work on one color will be totally trivial. By way of support for this, I have several programs - including those running on mobiles - which do color manipulation at a per-pixel level on largish images where I am doing RGB->HSB->(some manipulation)->RGB. Even performing this operation 100,000 times on an ipad only results in a delay of a couple of seconds - so on this relatively slow platform, I think your typical worst case conversion can be safely assumed to take less then 0.0001 seconds. And that's being pessimistic.

So just use whatever is easiest to code.

ADDED: to support the don't worry about this option. Internally a GPU will manipulate colors as an array of floats, so in C terms

float color[4];

or something similar. So the only conversion being done for the numeric options is a simple divide by 255.

On the other hand conversion of HSB to RGB takes considerably longer - I'd estimate, from having written code to do it, about 10 to 20 operations. So in crude terms HSB is considerably slower, BUT 20 (or even 20,000) operations on a modern GPU isn't worth worrying about - it's imperceptible.

Performance differences between color declarations?

If we assume a modern browser making full use of the GPU then the internal color representation will be RGB floats. Ignoring the color name - which is probably just a map to hex anyway - I think that hex and channels will be the fastest. HSB will undoubtedly be the slowest, as the conversion from HSB to RGB does require some work - about 50 lines of C code.

However, I think that for the purpose of CSS, this is a completely irrelevant question. Even for HSB to RGB the amount of work on one color will be totally trivial. By way of support for this, I have several programs - including those running on mobiles - which do color manipulation at a per-pixel level on largish images where I am doing RGB->HSB->(some manipulation)->RGB. Even performing this operation 100,000 times on an ipad only results in a delay of a couple of seconds - so on this relatively slow platform, I think your typical worst case conversion can be safely assumed to take less then 0.0001 seconds. And that's being pessimistic.

So just use whatever is easiest to code.

ADDED: to support the don't worry about this option. Internally a GPU will manipulate colors as an array of floats, so in C terms

float color[4];

or something similar. So the only conversion being done for the numeric options is a simple divide by 255.

On the other hand conversion of HSB to RGB takes considerably longer - I'd estimate, from having written code to do it, about 10 to 20 operations. So in crude terms HSB is considerably slower, BUT 20 (or even 20,000) operations on a modern GPU isn't worth worrying about - it's imperceptible.

Is there a performance difference between the different css color formats

From what I read in the article I linked below using HEX code is better but not by much we are talking if you have 100,000 colors in your code then it will create 1ms difference between them.

but you can visit this link to get a more meaning full understanding of why is doesn't make that much of a difference

and to see if it really makes a difference run an audit on your website and see the performance difference for each and see which one is better if any.
Link to answer

Are there any performance differences between color names or hexa values in css?

Putting away the color names, the hex values and RGB are pretty much the same.

But the result shows that Hex codes are slightly faster (not that much to worry about).

For example, Firefox 11 does 15,400 operations of hex code but 14,900 of rgb in a second.

So, that is not much to worry about. You won't even notice that.

What do the different shades of colors mean on an asset in the Chrome Devtools Timeline?

Figured this out.

Those shades correspond to whether the time is caused by the files "self" or the files "children":

Sample Image

I may be butchering this explanation, but "Self” refers to the length of time it takes for that specific file to load/execute, “children” references any additional files that get initiated by the parent, and the time they spend loading.

So it makes sense, in my original screenshot from the tweet, the “project-project” file is the file in our codebase that async loads other JS modules, so it makes sense that it would have a huge dark yellow section, since it is the one that initiates the requests for all those files.



Related Topics



Leave a reply



Submit