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

Don't invoke r.log() if not r.debug #1110

Merged
merged 1 commit into from
May 5, 2023

Conversation

colega
Copy link
Contributor

@colega colega commented Apr 5, 2023

Profiling shows that up to 40% of our allocations happen in r.markRead(): just to allocate a slice to pass the "remain" arg, which will be discarded because we don't run with r.debug=true.

  Total:    64259028   64259028 (flat, cum) 41.57%
    350            .          .           	if r.count == 0 { 
    351            .          .           		panic("markRead: negative count") 
    352            .          .           	} 
    353            .          .           	r.count-- 
    354            .          .           	r.unwindStack() 
    355     64259028   64259028           	r.log("Mark read remain=%d", r.remain) 
    356            .          .           } 
    357            .          .            
    358            .          .           func (r *messageSetReader) unwindStack() { 
    359            .          .           	for r.count == 0 { 
    360            .          .           		if r.remain == 0 { 

This makes the code slightly verbose, having to check the debug mode before invoking r.log(), but it's a huge difference in high-throughput applications.

@colega colega changed the title Don't invoce r.log() if not r.debug Don't invoke r.log() if not r.debug Apr 5, 2023
Profiling shows that up to 40% of our allocations happen in
r.markRead(): just to allocate a slice to pass the "remain" arg, which
will be discarded because we don't run with r.debug=true.

This makes the code slightly verbose, having to check the debug mode
before invoking r.log(), but it's a huge difference in high-throughput
applications.

Signed-off-by: Oleg Zaytsev <mail@olegzaytsev.com>
@rhansen2
Copy link
Collaborator

Hi @colega, Thanks for the contribution!

These changes look good to use. Just to verify, do you have a profile to share with these changes merged? If these debug lines are so impactful for performance we're also open to removing them entirely. Thanks!

@colega
Copy link
Contributor Author

colega commented May 4, 2023

👋 Hey, we're running with this change, and this function doesn't appear in the profiles anymore. It has zero impact disabled. I guess it's not harmful to leave the debug logs in case someone needs to see them.

@rhansen2 rhansen2 merged commit 5e7b724 into segmentio:main May 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants