Skip to content

Name magic numbers + minor cache performance#5

Open
AmityWilder wants to merge 1 commit into
SindexMon:mainfrom
AmityWilder:patch-1
Open

Name magic numbers + minor cache performance#5
AmityWilder wants to merge 1 commit into
SindexMon:mainfrom
AmityWilder:patch-1

Conversation

@AmityWilder

Copy link
Copy Markdown

Multiple magic numbers were present in array sizes, so I've given them constants for clarity.

Additionally, the inverse square root of 2 was being calculated at runtime when it could easily be a constant itself. I've also made one of the if-statements branchless, making it hopefully easier for the optimizer to speed up that loop. Ideally it could use a call to popcount, but I'm not certain what version of C++ this is designed for and the bits header doesn't have portable support for that feature in older versions.

I've also swapped the X and Y loops in dct8x8 to improve cache performance, since the input is row-major. Doing this gives the loops better locality since it's just sprinting through the elements in order rather than jumping row by row and then back to start the next column. This will hopefully improve the cache hit-rate. Note that this is simply a speed improvement. The cache I'm referring to is the CPU's cache of the RAM, not the browser's cache of media.

Multiple magic numbers were present in array sizes, so I've given them constants for clarity.

Additionally, the inverse square root of 2 was being calculated at runtime when it could easily be a constant itself. I've also made one of the if-statements branchless, making it hopefully easier for the optimizer to speed up that loop. Ideally it could use a call to `popcount`, but I'm not certain what version of C++ this is designed for and the bits header doesn't have portable support for that feature in older versions.

I've also swapped the X and Y loops in `dct8x8` to improve cache performance, since the `input` is row-major. Doing this gives the loops better locality since it's just sprinting through the elements in order rather than jumping row by row and then back to start the next column. This will hopefully improve the cache hit-rate.
Note that this is simply a speed improvement. The cache I'm referring to is the CPU's cache of the RAM, not the browser's cache of media.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant