Skip to content

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

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

Merged
merged 1 commit into from
Apr 5, 2023
Merged

Conversation

colega
Copy link
Collaborator

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

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 <[email protected]>
@colega colega force-pushed the call-r-log-only-if-debug branch from e4b7f6d to adab849 Compare April 5, 2023 16:00
Copy link

@replay replay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀

@replay
Copy link

replay commented Apr 5, 2023

are you planning to PR upstream as well?

@colega
Copy link
Collaborator Author

colega commented Apr 5, 2023

Yes, already sent in segmentio#1110

@colega colega merged commit a2f2e54 into main Apr 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.

2 participants