0

This is just a vague question based on curiosity.

Let's say I was storing colours in a database as just the hex value (ignore keys). The application should display the hex value and the RGB value.

I'm wondering if it would be better to store the RGB values in the database as well or use a JavaScript function on the hex value to produce the RGB after the query. The function is only like four lines and naturally the query would be the same but would return more data.

Would there be any discernible difference in performance? Presumably you would only really start to notice any if there were hundreds of thousands of entries.

Which method makes more sense conceptually?

1
  • You should store the integer representation of the color in the database, and translate it to whatever display format you want after the data is selected. Performance really doesn't matter. Commented Feb 25, 2014 at 4:40

1 Answer 1

1

Given you don't intend to operate on the color data (sort,filter,performs math on), you are just storing it so it doesn't really matter. I would probably store in the format you want to consume it in, since I presume you have a high read to write ratio.

Sign up to request clarification or add additional context in comments.

1 Comment

Yeah that seems to make the most sense. Consider retrieving the same colour 100,000 times; one method only runs the RGB function once, whereas the other has to run it every time. Even if the performance impact is negligible, it's just more sensible to minimize needless repetition.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.