Skip to content

When ECMA Script 2017 is adopted, use Map.entries() to make map range 2x faster. #1142

@tomconnell-wf

Description

@tomconnell-wf

In #1135 and #1136, ECMA Script 2015 support allowed the use of Javascript Maps to significantly speed up len() calls on maps. Yet, range loops on maps are significantly slower than on slices. Using the benchmarks in map_test.go:

goos: js
goarch: ecmascript
...
BenchmarkSliceRange         	  230768	      4849 ns/op
BenchmarkMapRange           	    6450	    184651 ns/op 
PASS

ECMA Script 2017 added the entries() call to Javascript Maps, allowing simplification of the RangeStmt:
https://github.com/gopherjs/gopherjs/compare/master...tomconnell-wf:gopherjs:js_map_entires?expand=1

Making this simple change makes map range statements over twice as fast:

goos: js
goarch: ecmascript
...
BenchmarkSliceRange         	  226414	      4876 ns/op
BenchmarkMapRange           	   19509	     61510 ns/op
PASS

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions