-
Notifications
You must be signed in to change notification settings - Fork 226
Fix bad scaling in rbs_comment_t tokens
#2578
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| com->tokens = rbs_allocator_calloc(allocator, com->line_size, rbs_token_t); | ||
| memcpy(com->tokens, p, sizeof(rbs_token_t) * com->line_count); |
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.
This was just re-implementing realloc
src/parser.c
Outdated
| static rbs_comment_t *alloc_comment(rbs_allocator_t *allocator, rbs_token_t comment_token, rbs_comment_t *last_comment) { | ||
| rbs_comment_t *new_comment = rbs_allocator_alloc(allocator, rbs_comment_t); | ||
|
|
||
| size_t initial_line_size = 10; |
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.
This is the same initial size this code used to use before. I haven't spent any time tuning it.
8c30976 to
1dbb362
Compare
1dbb362 to
c0c8021
Compare
| size_t line_tokens_capacity; | ||
| size_t line_tokens_count; | ||
| rbs_token_t *line_tokens; |
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.
This naming was confusing, because line_size sounds like "the size of a line".
What is actually means is "the capacity of the line_tokens buffer.
| } | ||
|
|
||
| static void comment_insert_new_line(rbs_allocator_t *allocator, rbs_comment_t *com, rbs_token_t comment_token) { | ||
| if (com->line_count == 0) { |
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.
By changing alloc_comment() to not call comment_insert_new_line(), we never have to deal with the 0 case here 🥳
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!
|
@amomchilov Can you take a look at the clang-format failure? Simply rebasing the branch on the top of master would solve the issue. |
c0c8021 to
be715d4
Compare
|
@soutaro Done! |
Fix bad scaling in `rbs_comment_t` tokens
Fix bad scaling in `rbs_comment_t` tokens
line_sizewas growing arithmetically (+ 10) rather than geometrically (* 2). I chose* 2because it's a popular choice and matchesrbs_buffer_t.Here's some stats on the number of lines per comment
You can see a huge left skew:
77% of comments are 20 lines or less:
Allocation stats
Before
These tables show how many comments required a particular number of reallocations.
After
By some rough numbers, I think this changes reduces needless memory copying from 5.79TB to only 0.89 TB.