Open navytux opened 7 years ago
Based on the recent responses I am going to close this issue as the current question has been answered and is unrelated to the original inquiry several years ago.
For future commenters—please open a new issue; fill out the template, explain your problem, give a procedure for someone else to reproduce what you are seeing and if it turns out this is an issue, it will be addressed.
Thank you all.
@davecheney, why do you close the issue? Even if nodejs is doing runtime map magic which Go is not willing to accept (but see P.S.), it was already explicitly posted here 3 years ago that:
https://github.com/golang/go/issues/19495#issuecomment-289293859
Why that information is being ignored?
Please reopen the issue, Kirill
P.S.
Personally I would also say that since small / medium maps are used everywhere all the time, it makes sense to put V8 style optimization into maps runtime, instead of forcing all programs to be manually rewritten. I would say that by speeding up maps, already existing Go code like fmt
, json
and similar packages would be automatically speed up too.
@navytux since the original issue was a comparison with V8 (which seems to be fixed, aside from the sequential-keys case), and your comment is a comparison with Pypy, maybe it makes sense to open a new issue for that comparison?
EDIT: however, that doesn't mean this shouldn't be reopened, if the discussion above suggested further optimizations which haven't been tried.
( I'm taking time break due to overload; I hope to reply to @networkimprov in 1 or 2 months. I appologize for the inconvenience )
Please answer these questions before submitting your issue. Thanks!
What did you do?
Hello up there. Map performance was already discussed some time ago in #3885 and improved a bit. It was also said there that the map algorithm is choosen to work very well with very very large maps. However maps are not always very very large and imho in many practical cases they are small and medium.
So please consider the following 3 programs:
(https://play.golang.org/p/rPH1pSM1Xk)
The time it takes to run them on i7-6600U is as follows:
The go version is 9.5x slower than javascript one, and ~ 1.8x slower than pypy one.
If we reduce the actual map size from 64K elements to 128 elements, activating the
a[i & 0x7f] = i
case via e.g. the following patch:timings become:
javascript becomes only a bit faster here while go & pypy improved ~ 2.3x / 2.2x respectively. Still go is 4x slower than javascript and 1.7x slower than pypy.
We can also test how it works if we do not limit the map size and let it grow on every operation. Yes, javascript and pypy are more memory hungry and for original niter=1E8 I'm getting out-of-memory in their cases on my small laptop, but let's test with e.g. niter=1E7 (diff to original program):
timings become:
So it is go/js ~6.5x slower and go/pypy is ~2.2x slower.
The profile for original program (
a[i & 0xffff] = i
) is:What did you expect to see?
Map operations for small / medium maps are as fast or better than in nodejs.
What did you see instead?
Map operations are 4x-10x slower than in javascript for maps sizes that are commonly present in many programs.
Does this issue reproduce with the latest release (go1.8)?
Yes.
System details
Thanks beforehand, Kirill
/cc @rsc, @randall77