split pTreeList into struct-of-arrays: eliminates multiply in hot loop#113
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves raw LZW encoding performance by refactoring the per-node “tree list” representation from an array-of-struct-like layout into a struct-of-arrays layout, removing a * 3 index multiply from a hot path.
Changes:
- Split
pTreeListinto three dedicateduint16_tarrays:pTreeListMap,pTreeListColor, andpTreeListIdx. - Update dictionary reset, child insertion, and tree crawl logic to use the new arrays.
- Update allocation and cleanup to manage the three arrays.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
dloebl
force-pushed
the
optimize-lzw-treelist
branch
from
March 24, 2026 13:56
771ac2c to
7c16f5a
Compare
MCLoebl
approved these changes
Mar 30, 2026
MCLoebl
left a comment
Collaborator
There was a problem hiding this comment.
If the variable names make sense to you, please merge. Could you check if the speed improvement is still there for more noisy (real) images? When pTreeMap is needed more, the speed improvement may be smaller I guess.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Improve raw LZW encoding speed by ~30% (ARM) / ~12% (x86) by splitting
pTreeListinto separate arrays:pTreeListstored 3uint16_tfields per node, requiring a* 3multiply on every access in the hot loop. Splitting into three individual arrays (pTreeListMap,pTreeListColor,pTreeListIdx) eliminates the multiply - each array is indexed directly byparentIndex.