Repository navigation
Closed
Labels
Milestone
Description
by yury.shulaev:
I did a trivial map benchmark using Go (gc), JavaScript (V8) and Python (Python3, PyPy) and here are the results: $ export GOMAXPROCS=""; go build map.go; time ./map real 0m0.656s user 0m0.652s sys 0m0.000s $ time node map.js real 0m0.055s user 0m0.040s sys 0m0.012s $ time python3 map.py real 0m0.613s user 0m0.592s sys 0m0.016s $ time pypy map.py real 0m0.143s user 0m0.124s sys 0m0.016s Looks like Go's map is 12 times slower than V8's and 4.5 times slower than PyPy's. Well, JavaScript objects can only use strings as keys, but Python's dict does not have this limitation and it is still being able to run in 0.143s. Is it possible to adapt V8's map implementation to Go? By the way, it looks simpler: https://github.com/v8/v8/blob/master/src/hashmap.h vs http://code.google.com/p/go/source/browse/src/pkg/runtime/hashmap.c Code used in the benchmark: map.go: package main func main() { a := make(map[int]int) for i := 0; i < 10000000; i++ { a[123] = 456 } } map.js: function main() { var a = {}; for (var i = 0; i < 10000000; i++) { a[123] = 456; } } main(); map.py: #!/usr/bin/env python3 def main(): a = {} for i in range(10000000): a[123] = 456 if __name__ == '__main__': main() Profiler output for 10 times more iterations: Total: 772 samples 385 49.9% 49.9% 504 65.3% hash_lookup 106 13.7% 63.6% 106 13.7% runtime.memhash 86 11.1% 74.7% 86 11.1% runtime.rnd 60 7.8% 82.5% 618 80.1% runtime.mapaccess 37 4.8% 87.3% 37 4.8% runtime.memcopy32 33 4.3% 91.6% 765 99.1% main.main 32 4.1% 95.7% 732 94.8% runtime.mapaccess1 20 2.6% 98.3% 20 2.6% hash_indirect 13 1.7% 100.0% 13 1.7% runtime.memequal32 0 0.0% 100.0% 765 99.1% runtime.main OS and hardware: Linux 3.2.0-27-generic #43-Ubuntu SMP Fri Jul 6 14:25:57 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux go version go1 (which is 'apt-get install golang') Intel Core i5, 4 GB RAM
Activity
remyoudompheng commentedon Jul 29, 2012
Comment 1:
gopherbot commentedon Jul 29, 2012
Comment 2 by yury.shulaev:
gopherbot commentedon Jul 29, 2012
Comment 3 by yury.shulaev:
gopherbot commentedon Jul 31, 2012
Comment 4 by yury.shulaev:
gopherbot commentedon Jul 31, 2012
Comment 5 by yury.shulaev:
rsc commentedon Sep 12, 2012
Comment 6:
Labels changed: added priority-later, removed priority-triage.
Status changed to Accepted.
rsc commentedon Sep 12, 2012
Comment 7:
Labels changed: added go1.1maybe.
gopherbot commentedon Sep 13, 2012
Comment 8 by yury.shulaev:
rsc commentedon Sep 13, 2012
Comment 9:
rsc commentedon Dec 10, 2012
Comment 11:
Labels changed: added size-l.
randall77 commentedon Mar 12, 2013
Comment 12:
This issue was updated by revision a5d4024.
rsc commentedon Mar 12, 2013
Comment 13:
Labels changed: removed go1.1maybe.
ugorji commentedon Mar 14, 2013
Comment 14:
I was seeing some bad results within my codebase that looked up information within a map. I had to look up a mapping for reflect.Type every turn in the loop and the map access increased my benchmark times significantly. I did some analysis comparing to Node.JS maps, for both string and integer key/values, checking time spent for inserts, deletes and gets for different sizes of the map. I've attached 4 files with my results: - comparelangs.go - comparelangs.js - test.sh (for running with appropriate arguments) - output.txt (output from a sample run). Simple Analysis Results: Node.JS significantly better than Go Maps for insert and retrieval. Go Maps performance degrades at retrieval as map size increases. Node.JS terrible/unusable at delete once since of map grows. Summary is that for typical map usage of small size maps that are, mostly doing retrievals, Go maps do not perform as well.Attachments:
ugorji commentedon Mar 14, 2013
Comment 15:
Attachments:
rsc commentedon Mar 15, 2013
Comment 16:
Labels changed: added go1.1maybe.
Owner changed to @randall77.
Status changed to Started.
ugorji commentedon Mar 15, 2013
Comment 17:
bradfitz commentedon Mar 19, 2013
Comment 18:
Attachments:
randall77 commentedon Mar 20, 2013
Comment 19:
This issue was updated by revision 00224a3.
robpike commentedon May 18, 2013
Comment 20:
Labels changed: added go1.2maybe, removed go1.1maybe.
rsc commentedon Jul 30, 2013
Comment 21:
robpike commentedon Aug 7, 2013
Comment 22:
Status changed to Fixed.