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

x/blog: pprof example doesn't trigger reallocation #43963

Open
vorishirne opened this issue Jan 28, 2021 · 3 comments
Open

x/blog: pprof example doesn't trigger reallocation #43963

vorishirne opened this issue Jan 28, 2021 · 3 comments
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@vorishirne
Copy link

vorishirne commented Jan 28, 2021

What version of Go are you using (go version)?

$ go version
go version go1.15.6 linux/amd64

Does this issue reproduce with the latest release?

Not related

What operating system and processor architecture are you using (go env)?

i5/ubuntu

What did you do?

In the golang blog of pprof, they demonstrate the performance of golang via a benchmarking code and then comparing with cpp counterpart. The blog tells about reallocartion of memory and its time complexities in multiple loops.

The blog => https://blog.golang.org/pprof

So, I builded the examples mentioned in the havlak repository.
But to find out, that the variable "size" is static throught the execution, to be precise, 252013.

What did you expect to see?

The constant value of size parameter, doesn't triggers the the memory re-allocation, measuring whose cost is the most focused part of the blog.

What did you see instead?

As the blog uses the havlok example as a memory critical task, It isn't actually.

@vorishirne vorishirne changed the title Code used in Golang pprof blog, to demonstrate performance of golang doesnt do what it does Code used in Golang pprof blog, to demonstrate performance of golang doesn't comply against what expressed in the blog Jan 28, 2021
@davecheney
Copy link
Contributor

davecheney commented Jan 28, 2021

Did you include a link to the blog post?

@vorishirne
Copy link
Author

Added in issue description, https://blog.golang.org/pprof

@seankhliao seankhliao changed the title Code used in Golang pprof blog, to demonstrate performance of golang doesn't comply against what expressed in the blog x/blog: pprof example doesn't trigger reallocation Jan 28, 2021
@gopherbot gopherbot added this to the Unreleased milestone Jan 28, 2021
@seankhliao seankhliao added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 28, 2021
@vorishirne
Copy link
Author

To add more context, printing here the diff of edited source code, and the output

diff --git a/../havlak/havlak6.go b/havlak6.go
index 39b2e3c..5530dd0 100644
--- a/../havlak/havlak6.go
+++ b/havlak6.go
@@ -291,6 +291,7 @@ func (f *LoopFinder) FindLoops(g *CFG, lsg *LoopGraph) {
        }
 
        // Step A: Initialize nodes, depth first numbering, mark dead nodes.
+       fmt.Println(size,cap(f.LoopBlock))
        if size <= cap(f.LoopBlock) {
                f.LoopBlock = f.LoopBlock[:size]
                f.DepthFirst = f.DepthFirst[:0]

For cpp code,

$ git diff ../havlak/havlak6.cc havlak6.cc
diff --git a/../havlak/havlak6.cc b/havlak6.cc
index 22afbdc..74ead0f 100644
--- a/../havlak/havlak6.cc
+++ b/havlak6.cc
@@ -269,7 +269,9 @@ void LoopFinder::FindLoops(CFG *g, LoopGraph *lsg) {
                return;
 
        // Step A: Initialize nodes, depth first numbering, mark dead nodes.
-       this->loopBlock.resize(size);
+       printf("%lu %d\n",loopBlock.size(),size);
+       if (0 < size){
+       this->loopBlock.resize(size);}
        this->depthFirst.reserve(size);
        this->depthFirst.clear();
        for (int i = 0; i < size; i++)

Program output :

$ ./xtime ./havlak6
252013 0
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
252013 252013
# of loops: 76000 (including 1 artificial root node)
2.77u 0.04s 2.53r 85940kB ./havlak6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants