On 7 November 2017 at 15:06, Ben Hoyt <benh...@gmail.com> wrote:

>
> 2x as fast as CPython sounds pretty good to me -- nice!
>>>
>>
No, CPython is 2x as fast as Skylark in Go.  It's implemented in C, so it
can do things that are sadly impossible in Go, like implement a threaded
bytecode interpreter.


I'm curious why you wrote the dict implementation from scratch
> (hashtable.go) instead of using Go maps as a base, and adding a secondary
> data structure (slice of keys?) to keep track of insertion order? I'm
> presuming there's a good technical reason, but at first glance it seems
> like it would be faster and simpler to use Go maps to start with.
>

There are many reasons Go maps would not work.  First, they do not allow
you to define the hash function and equivalence relation for keys.  Skylark
considers 1.0 == 1, for instance, whereas Go does not; also.  Second, Go
maps require that keys be comparable, but Skylark tuples are represented as
slices, for example. Third, Go maps have non-deterministic iteration order
whereas Skylark maps are ordered by insertion. You could maintain a
separate slice of keys for the iteration order, but at that point you're
halfway to building you're own hash table.

Why should Go maps be faster?  Go's map is implemented in Go.  There's no
reason a different implementation should be equally fast, or perhaps even
faster.  The basic design of the Skylark-in-Go hash table is actually very
similar to Go's map.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to