10000 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
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions probe/probe.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ func (p *Probe) report() report.Report {

result := report.MakeReport()
for i := 0; i < cap(reports); i++ {
result = result.Merge(<-reports)
result.UnsafeMerge(<-reports)
}
return result
}
Expand All @@ -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.

ForLoop:
for {
select {
case r := <-rs:
rpt = rpt.Merge(r)
rpt.UnsafeMerge(r)
default:
break ForLoop
}
Expand Down
0