-
Notifications
You must be signed in to change notification settings - Fork 291
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
cleanup: Small improvements found by PVS Studio. #2666
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #2666 +/- ##
==========================================
- Coverage 73.11% 73.02% -0.09%
==========================================
Files 148 148
Lines 30487 30482 -5
==========================================
- Hits 22292 22261 -31
- Misses 8195 8221 +26 ☔ View full report in Codecov by Sentry. |
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.
Reviewed 5 of 6 files at r1, all commit messages.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @iphydf)
toxcore/group_chats.c
line 2601 at r1 (raw file):
{ static_assert(sizeof(GC_Peer) < 2048, "GC_Peer is too large for stack allocation"); GC_Peer self = {0};
Why is it stack-allocated now and we have the assert in case it the struct becomes too large... that feels like the step in the wrong direction, no?
Is it simply because the heap allocation is unnecessary in here since the object doesn't outlive the function scope, or is there a greater reason for this?
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.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @nurupo)
toxcore/group_chats.c
line 2601 at r1 (raw file):
Previously, nurupo wrote…
Why is it stack-allocated now and we have the assert in case it the struct becomes too large... that feels like the step in the wrong direction, no?
Is it simply because the heap allocation is unnecessary in here since the object doesn't outlive the function scope, or is there a greater reason for this?
To add to this, what is the significance of 2048 bytes? I seem to recall that we try to keep stack allocations well below a certain threshold for musl builds but I can't remember what it is.
2048 is half a memory page, so it was a nice round number. I could make the assert check for tox max packet size instead, which is what we frequently stack-allocate everywhere, but there's no relationship between peer struct size and packet size, other than that both can be stack allocated. |
49068b0
to
7342232
Compare
Um. Kindly pointing out that my questions weren't rhetorical :D |
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.
Reviewable status: 1 change requests, 0 of 1 approvals obtained (waiting on @nurupo)
toxcore/group_chats.c
line 2601 at r1 (raw file):
Previously, JFreegman wrote…
To add to this, what is the significance of 2048 bytes? I seem to recall that we try to keep stack allocations well below a certain threshold for musl builds but I can't remember what it is.
musl builds can't have stacks larger than 131072 bytes. So if we have a call stack 64 levels deep, and every level allocates 2KB, then we run out on musl.
Indeed it's just because the object doesn't outlive the function scope.
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.
Reviewed 2 of 2 files at r2, 2 of 2 files at r3, all commit messages.
Reviewable status: complete! 1 of 1 approvals obtained
This change is