Comments (3)
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 int64
s, and three immutable string
s. 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.
@sdboyer thanks for providing the detail and those pointers (pun intended).
from semver.
Closing because this has been merged.
from semver.
Related Issues (20)
- Fault tolerant constraints HOT 2
- match on build metadata HOT 2
- Zero Major Caret Special Case HOT 1
- Select only prereleases HOT 1
- This should be a CLI HOT 1
- Constraint for exact version match HOT 4
- Distinguish between zero values and missing values HOT 1
- Allow pre-releases when only used for one part of a range? HOT 5
- `Checking Version Constraints` is unpredictable while patch is missing in version string
- Caret operator (^) gives unexpected results when the minor version in constraint is 0(zero)
- NewConstraint method faulty behavior HOT 6
- Valid constraints fails to parse HOT 2
- v1 - issue with major only constraint HOT 4
- Release of new versions HOT 1
- gob: type semver.Version has no exported fields HOT 2
- `20221209-update-renovatejson-v4` tag does not fail NewVersion test HOT 2
- Improper version constraint HOT 1
- improper constraint error when parsing a constraint with ranges and space separated parts HOT 1
- Ruby pre release support HOT 1
- semver v3 regex is more inclusive than the official semver.org regex HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from semver.