8000 perf(probe): reduce copying of nodes by bboreham · Pull Request #3679 · weaveworks/scope · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

perf(probe): reduce copying of nodes #3679

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
Sep 18, 2019
Merged

perf(probe): reduce copying of nodes #3679

merged 1 commit into from
Sep 18, 2019

Conversation

bboreham
Copy link
Collaborator

Where we know we are merging several reports into the one, we can call UnsafeMerge() and skip the copy that Merge() will do.

Small impact; most of the effort goes into collecting the data not publishing it.

Where we know we are merging several reports into the one, we can call
UnsafeMerge() a
8000
nd skip the copy that Merge() will do.
@bboreham bboreham requested a review from qiell as a code owner September 15, 2019 16:41
Copy link
Contributor
@fbarl fbarl left a comment

Choose a reason for hiding this comment

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

LGTM! 👍

@@ -210,11 +210,12 @@ func (p *Probe) tag(r report.Report) report.Report {

func (p *Probe) drainAndPublish(rpt report.Report, rs chan report.Report) {
p.rateLimiter.Wait(context.Background())
rpt = rpt.Copy()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Does the rpt report.Report in the function arg only do a shallow copy? If it's a deep copy, then we don't need this line, if it's shallow, then why not only pass the reference there rpt *report.Report?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Since Report holds some slices and maps, copying it is shallow so we need the deep copy.
However in Go it is idiomatic to pass a reference only where you intend to modify the data, or when profiling shows the reference to be way more efficient.

@bboreham bboreham merged commit 71a359e into master Sep 18, 2019
@bboreham bboreham deleted the probe-unsafe-merge branch September 18, 2019 14:56
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
0