Skip to content

cleanup: Small improvements found by PVS Studio.#2666

Merged
toktok-releaser merged 1 commit into
TokTok:masterfrom
iphydf:pvs-cleanups
Feb 11, 2024
Merged

cleanup: Small improvements found by PVS Studio.#2666
toktok-releaser merged 1 commit into
TokTok:masterfrom
iphydf:pvs-cleanups

Conversation

@iphydf

@iphydf iphydf commented Feb 9, 2024

Copy link
Copy Markdown
Member

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
@codecov

codecov Bot commented Feb 9, 2024

Copy link
Copy Markdown

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.

@nurupo nurupo left a comment

Copy link
Copy Markdown
Member

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?

@JFreegman JFreegman left a comment

Copy link
Copy Markdown
Member

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

iphydf commented Feb 9, 2024

Copy link
Copy Markdown
Member Author

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

nurupo commented Feb 9, 2024

Copy link
Copy Markdown
Member

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

@iphydf iphydf left a comment

Copy link
Copy Markdown
Member Author

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

@nurupo nurupo left a comment

Copy link
Copy Markdown
Member

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
@iphydf
iphydf deleted the pvs-cleanups branch January 1, 2026 06:54
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