Skip to content
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

Merged
merged 1 commit into from
Feb 11, 2024

Conversation

iphydf
Copy link
Member

@iphydf iphydf commented Feb 9, 2024

This change is Reviewable

@iphydf iphydf added this to the v0.2.19 milestone Feb 9, 2024
@iphydf iphydf marked this pull request as ready for review February 9, 2024 01:43
Copy link

codecov bot commented Feb 9, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (8201019) 73.11% compared to head (961891d) 73.02%.

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.
📢 Have feedback on the report? Share it here.

Copy link
Member

@nurupo nurupo left a 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?

Copy link
Member

@JFreegman JFreegman left a 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.

@iphydf
Copy link
Member Author

iphydf commented Feb 9, 2024

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.

@iphydf iphydf force-pushed the pvs-cleanups branch 2 times, most recently from 49068b0 to 7342232 Compare February 9, 2024 02:49
@nurupo
Copy link
Member

nurupo commented Feb 9, 2024

Um. Kindly pointing out that my questions weren't rhetorical :D

Copy link
Member Author

@iphydf iphydf left a 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.

@iphydf iphydf modified the milestones: v0.2.19, v0.2.20 Feb 11, 2024
Copy link
Member

@nurupo nurupo left a 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: :shipit: complete! 1 of 1 approvals obtained

@iphydf iphydf modified the milestones: v0.2.20, v0.2.19 Feb 11, 2024
@toktok-releaser toktok-releaser merged commit 961891d into TokTok:master Feb 11, 2024
60 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants