Skip to content

misc: Prevent Vec_IntRemove from loading nSize in every iteration#508

Open
mshockwave wants to merge 1 commit into
berkeley-abc:masterfrom
mshockwave:patch/fix-vec-int-nSize-reload
Open

misc: Prevent Vec_IntRemove from loading nSize in every iteration#508
mshockwave wants to merge 1 commit into
berkeley-abc:masterfrom
mshockwave:patch/fix-vec-int-nSize-reload

Conversation

@mshockwave
Copy link
Copy Markdown

This seemly benign loop

for ( i++; i < p->nSize; i++ )
  p->pArray[i-1] = p->pArray[i];

will actually load p->nSize in every loop iteration (rather than memorizing the value) due to some unfortunate pointer aliasing properties in C/C++. As Vec_IntRemove is quite ubiquitous, this extra memory load actually causes visible performance impact and prevents further optimizations on the loop.

This patch fixes this by factoring p->nSize out of the loop.

This seemly benign loop
```
for ( i++; i < p->nSize; i++ )
  p->pArray[i-1] = p->pArray[i];
```

will actually load `p->nSize` in every loop iteration (rather than
memorizing the value) due to some unfortunate pointer aliasing properties
in C/C++. As Vec_IntRemove is quite ubiquitous, this extra memory load
actually causes visible performance impact and prevents further
optimizations on the loop.

This patch fixes this by factoring `p->nSize` out of the loop.
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