On Tue, Nov 7, 2017 at 3:16 PM, Alan Donovan <adono...@google.com> wrote:

> 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.
>

Sorry, I actually grokked what you said but then repeated it incorrectly. I
meant to say: half as fast as CPython sounds pretty good.

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.
>

Thanks for the thorough response, that's really helpful.

I hadn't yet realized that Go maps don't allow you to define the hash /
equality functions.

And good point about Go's map also being implemented in Go too. I'm a lot
more familiar with CPython internals, and was kind of assuming Go maps were
written in C+asm, but it looks like the entire runtime is written in Go now
(with a bit of assembly).

-Ben

-- 
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