Git Product home page Git Product logo

Comments (7)

name5566 avatar name5566 commented on June 27, 2024

I agree with @robzan8. It make a misunderstanding on Gob. Gob is the same fast as protobuf in my tests.

from go_serialization_benchmarks.

alecthomas avatar alecthomas commented on June 27, 2024

I'd welcome a PR for this. I tried, but kept getting corrupt message errors:

BenchmarkGobMarshal-8    1000000          1207 ns/op          48 B/op          2 allocs/op
BenchmarkGobUnmarshal-8 b=61
--- FAIL: BenchmarkGobUnmarshal-8
    serialization_benchmarks_test.go:114: gob failed to unmarshal: gob: unknown type id or corrupted data (<��b9b2b4faa77947cf�4���IL�
        1ca61f574b��Y�K���?)
ok      github.com/alecthomas/go_serialization_benchmarks   1.244s

from go_serialization_benchmarks.

robzan8 avatar robzan8 commented on June 27, 2024

I'm pretty sure I understand where the issue comes from.
The first time a gob encoder encodes a value of a certain type that has never encountered before, it also transmits type information needed by the decoder for that type.
in function benchUnmarshal, ser[0] also contains serialized type info that is needed to decode elements of type A. So, for everything to work correctly, ser[0] should be the first thing decoded by the decoder.
Unfortunately, the decoder chooses at random what to decode, and it reports that a value with unknown type id has been encountered.
To fix the problem, ser[0] should be decoded only once, before anything else (before some other ser[i]). Another thing that may work is calling gob.Register(a) (where "a" is a value of type A), before doing the encoding/decoding (former method works for sure, I'm not sure about the latter).
I may be able to do a PR in the next few days.

from go_serialization_benchmarks.

robzan8 avatar robzan8 commented on June 27, 2024

I can't run the benchmarks on master because zombiezen.com/go/capnproto2 has been moved.
I tried go-getting https://github.com/zombiezen/go-capnproto2
but I get the following error:
can't load package: package github.com/zombiezen/go-capnproto2: code in directory $GOPATH/src/github.com/zombiezen/go-capnproto2 expects import "zombiezen.com/go/capnproto2"

Am I missing something?

from go_serialization_benchmarks.

alecthomas avatar alecthomas commented on June 27, 2024

zombiezen.com/go/capnproto2 uses a go-import meta redirect, so it should still work. It works for me:

[alec@cavern:~/Projects/go_serialization_benchmarks]go get -u zombiezen.com/go/capnproto2
[alec@cavern:~/Projects/go_serialization_benchmarks]

PS. Did you try using the Makefile? make clean && make install && make

from go_serialization_benchmarks.

robzan8 avatar robzan8 commented on June 27, 2024

zombiezen.com/go/capnproto2 was down yesterday when I tried; works now.

from go_serialization_benchmarks.

pascaldekloe avatar pascaldekloe commented on June 27, 2024

Before first use you to gob.Register. That's where the errors came from.

from go_serialization_benchmarks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.