GithubHelp home page GithubHelp logo

Comments (3)

sdboyer avatar sdboyer commented on July 21, 2024

A slightly more detailed explanation of the performance issue:

With the way that go's escape analysis works, creating and returning a pointer value from outside of the scope in which it was created will always result in a heap allocation. (Go's escape analysis is not very sophisticated right now). Avoiding small allocations are one of the first and major things you do to improve runtime performance - see, for example, this ol' Cloudflare piece.

Moreover, because of the typical use pattern for a version, you also get bit on GC. It's not uncommon - say, in vsolver - to create lots of *Version instances, even just ephemeral ones as part of a larger calculation. (The 2.x branch of this lib does this internally as well, with the new constraint calculation system.) This means creating lots of typically short-lived, small (almost always <100 bytes, often only 24 bytes), heap-allocated values. All of those become extraneous garbage that the GC has to deal with.

And, really, this is an easy win, because there's no intrinsic need for versions to be heap allocated. They consistent entirely of stack-allocable components - three int64s, and three immutable strings. If people want to use this library as a component in a serious, larger, and especially long-lived application, it shouldn't make allocations it doesn't have to, or make a needless mess for GC to clean up.

from semver.

mattfarina avatar mattfarina commented on July 21, 2024

@sdboyer thanks for providing the detail and those pointers (pun intended).

from semver.

mattfarina avatar mattfarina commented on July 21, 2024

Closing because this has been merged.

from semver.

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.