-
Notifications
You must be signed in to change notification settings - Fork 354
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Replaced threadvars and improved performance of Stretch() (when Curre…
…ntLineXxx were changed from global variables to threadvars the performance gain became a performance hit).
- Loading branch information
1 parent
d0c0a34
commit 4a6b0ae
Showing
2 changed files
with
182 additions
and
154 deletions.
There are no files selected for viewing
This file contains 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
Oops, something went wrong.
4a6b0ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But threadvars are inherently threadsafe, what are the consequences?
4a6b0ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data is now exchanged using parameters and should be thread safe this way (as far as I can understand this code).
4a6b0ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I read from the code is that when the code was initially written, the function used thread unsafe variables. Those had the advantage of saving one parameter leaving either a CPU register available or not using a stack parameter. Furthermore accessing the those global variables arrays reduced the CPU register pressure or number of temporaries on the stack because the compiler could use the absolute address in the code.
But when they were changed to threadvars (to make them thread-safe) every single access was automatically changed to a GetTLS function call by the compiler and all the benefits of being a global variable were gone.
The change that I made removes the threadvars arrays completely and combines them into one local array variable. That variable is then specified as argument to the functions that originally used the global/threadvar variables. So no global variable of any kind is used anymore, keeping the Stretch() function thread-safe (as far as TBitmap thread-safety is guaranteed).
4a6b0ae
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the explanation, I did not notice the replacement of global variables by parameters.