Git Product home page Git Product logo

Comments (4)

goccy avatar goccy commented on July 24, 2024 3

Unless you mention that your library is compatible with encoding/json, I think it's good to sacrifice functionality for performance 😄

However, if you want to compare performance with other libraries, you should, to be fair, see if the library you're comparing has an option that doesn't sort the map, and use that if any.
For example, json-iterator/go supported by SortMapKeys: false at config . ( Also, my library support too by json.UnorderedMap() option )

from sonic.

PureWhiteWu avatar PureWhiteWu commented on July 24, 2024

Is this a documented behaviour of the standard library?

from sonic.

goccy avatar goccy commented on July 24, 2024

See https://golang.org/pkg/encoding/json/#Marshal

The map keys are sorted and used as JSON object keys by applying the following rules, subject to the UTF-8 coercion described for string values above:

from sonic.

chenzhuoyu avatar chenzhuoyu commented on July 24, 2024

As you know, this behavior hurts performance A LOT, and it's specific to the Go StdLib, RFC8259 does NOT require sorting the keys.

This library is designed for performance, not a drop-in replacement of the StdLib, so we must drop some performance-killing "features", as long as it still meets the requirements of the RFC, it's a working implementation. It is OK to behave slightly different with the StdLib.

For reproducible tests, we might consider making it optional. You can then manually switch it on at the cost of some performance.

BTW, if you think the benchmark result is unfair, you can always disable key sorting in your library, and benchmark again.

Marked low-priority now.

from sonic.

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.