Reduce memory writes and short-lived allocations.#17
Open
cbiffle wants to merge 1 commit intozserge:masterfrom
Open
Reduce memory writes and short-lived allocations.#17cbiffle wants to merge 1 commit intozserge:masterfrom
cbiffle wants to merge 1 commit intozserge:masterfrom
Conversation
e8e8b6f to
4ce0dd9
Compare
I noticed that hot parts of the program (allocation and evaluation) were doing more work than is strictly necessary, so I've removed some of it. - Removed the memset from tcl_append_string, since all but one byte of it is immediately overwritten by strncpy. Just zeroed the terminating byte instead. - Loosened the return type of tcl_string to char* (not const), since many uses of it mutate the returned buffer. - Replaced the initializing copy in tcl_append_string with memcpy, which is slightly faster than strncpy in cases like this where the length is known in advance. (This is about a 5% improvement in my tests.) - Altered tcl_append to _not_ free the right-hand argument, after noticing that almost every use of it created an otherwise-unused copy. - In TCMD handling, rely on tcl_list_at to detect an empty command by returning NULL. This avoids a second tokenization pass over the string in tcl_list_length. - Avoid making a short-lived copy of the value in tcl_var, just take ownership of the pointer instead. On a small collection of microbenchmarks, this improved performance by about 25-30% on my machine.
4ce0dd9 to
1c7284a
Compare
Author
|
(Noticed your suggestion to run clang-format on PRs, updated the commit accordingly -- it's done something odd to the TCMD case block, but now it's consistent.) |
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.
I noticed that hot parts of the program (allocation and evaluation) were doing more work than is strictly necessary, so I've removed some of it.
Removed the memset from tcl_append_string, since all but one byte of it is immediately overwritten by strncpy. Just zeroed the terminating byte instead.
Loosened the return type of tcl_string to char* (not const), since many uses of it mutate the returned buffer.
Replaced the initializing copy in tcl_append_string with memcpy, which is slightly faster than strncpy in cases like this where the length is known in advance. (This is about a 5% improvement in my tests.)
Altered tcl_append to not free the right-hand argument, after noticing that almost every use of it created an otherwise-unused copy.
In TCMD handling, rely on tcl_list_at to detect an empty command by returning NULL. This avoids a second tokenization pass over the string in tcl_list_length.
Avoid making a short-lived copy of the value in tcl_var, just take ownership of the pointer instead.
On a small collection of microbenchmarks, this improved performance by about 25-30% on my machine.