GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix: avoid re-instantiating SemVer during diff compare by macno · Pull Request #547 · npm/node-semver

Conversation

@macno

@macno macno commented Apr 12, 2023

Copy link
Copy Markdown
Contributor

Following #539 this small change improves speed by ~10% just calling compare directly on the semver object returned by parse

Performance on branch v7.4.0

╭─macno@cayenne ~/Projects/opensource/node-semver  ‹v7.4.0›
╰─➤  node benchmark.js
diff(0.0.1, 0.0.1) x 4,290,326 ops/sec ±0.34% (95 runs sampled)
diff(0.0.1, 0.0.1-pre) x 2,136,948 ops/sec ±0.06% (94 runs sampled)
diff(0.0.1, 0.0.1-pre-2) x 2,123,307 ops/sec ±0.12% (95 runs sampled)
diff(1.1.0, 1.1.0-pre) x 2,124,436 ops/sec ±0.12% (102 runs sampled)

And after the change

╭─macno@cayenne ~/Projects/opensource/node-semver  ‹main›
╰─➤  node benchmark.js
diff(0.0.1, 0.0.1) x 4,801,698 ops/sec ±0.30% (90 runs sampled)
diff(0.0.1, 0.0.1-pre) x 2,323,553 ops/sec ±0.06% (98 runs sampled)
diff(0.0.1, 0.0.1-pre-2) x 2,307,169 ops/sec ±0.14% (98 runs sampled)
diff(1.1.0, 1.1.0-pre) x 2,319,211 ops/sec ±0.11% (95 runs sampled)
benchmark.js
const Benchmark = require('benchmark')
const diff = require('./functions/diff')
const suite = new Benchmark.Suite()

const cases = [
  ['0.0.1', '0.0.1', null ],
  ['0.0.1', '0.0.1-pre', 'patch'],
  ['0.0.1', '0.0.1-pre-2', 'patch'],
  ['1.1.0', '1.1.0-pre', 'minor'],
]

for (const [v1, v2] of cases) {
  suite.add(`diff(${v1}, ${v2})`, function () {
    diff(v1, v2)
  })
}

suite
  .on('cycle', function (event) {
    console.log(String(event.target))
  })
  .run({ async: false })

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@macno
fix: faster diff avoiding twice instantiation of semver objects
21464fc
@macno
macno requested a review from a team as a code owner April 12, 2023 07:27
@macno
macno requested a review from wraithgar April 12, 2023 07:27
wraithgar
wraithgar approved these changes Apr 12, 2023
View reviewed changes
@wraithgar wraithgar changed the title fix: faster diff avoiding twice instantiation of semver objects fix: avoid re-instantiating SemVer during diff compare Apr 12, 2023
@wraithgar
wraithgar merged commit 2781767 into npm:main Apr 12, 2023
@github-actions github-actions Bot mentioned this pull request Apr 12, 2023
chore: release 7.5.0 #549
Merged
@snyk-bot snyk-bot mentioned this pull request May 16, 2023
[Snyk] Upgrade semver from 6.3.0 to 7.5.0 OutSystems/cordova-plugin-add-swift-support#3
Closed
@ms-bot ms-bot mentioned this pull request Jun 5, 2023
chore(deps): bump 🧳 semver to ^7.6.3 mobsuccess-devops/pmd-github-action#11
Closed
This was referenced Jul 31, 2023
Bump semver from 7.3.5 to 7.5.2 in /platform/ui ossrs/oryx#107
Closed
Bump semver from 7.3.5 to 7.5.4 in /platform/ui ossrs/oryx#111
Closed
Bump semver from 7.3.5 to 7.5.2 in /ui ossrs/oryx#116
Closed
This was referenced May 24, 2024
[Snyk] Upgrade semver from 7.3.7 to 7.6.0 NOUIY/npm-groovy-lint#71
Closed
[Snyk] Upgrade semver from 7.3.8 to 7.6.0 NOUIY/security-wg#55
Closed
@devcurt696 devcurt696 mentioned this pull request May 29, 2024
[Snyk] Upgrade semver from 7.0.0 to 7.6.1 devcurt696/resume-builder#77
Open
@NOUIY NOUIY mentioned this pull request May 30, 2024
[Snyk] Upgrade semver from 7.3.7 to 7.6.1 NOUIY/npm-groovy-lint#77
Closed
@fanibahar fanibahar mentioned this pull request May 30, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 fanibahar/juice-shop1#71
Open
@devcurt696 devcurt696 mentioned this pull request May 31, 2024
[Snyk] Upgrade semver from 7.0.0 to 7.6.2 devcurt696/resume-builder#78
Open
@NOUIY NOUIY mentioned this pull request May 31, 2024
[Snyk] Upgrade semver from 7.3.7 to 7.6.2 NOUIY/npm-groovy-lint#78
Closed
@Mhmonicox Mhmonicox mentioned this pull request Jun 1, 2024
[Snyk] Upgrade semver from 7.3.6 to 7.6.2 Mhmonicox/actions-setup-cmake#35
Open
@Haricthered Haricthered mentioned this pull request Jun 7, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 Haricthered/juice-shop#5
Open
@AndrewSnyk AndrewSnyk mentioned this pull request Jun 8, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 AndrewSnyk/juice-shop#5
Merged
@jessicazhanggg jessicazhanggg mentioned this pull request Jun 13, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 jessicazhanggg/juice-shop#6
Open
@monjie110 monjie110 mentioned this pull request Jun 22, 2024
[Snyk] Upgrade semver from 7.3.4 to 7.6.2 monjie110/vscode-go#4
Open
@Kavinpg96 Kavinpg96 mentioned this pull request Jun 25, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 Kavinpg96/nodejs.org#5
Open
@dulumina dulumina mentioned this pull request Jul 11, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 dulumina/WBOT#2
Open
This was referenced Jul 16, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 Exhorder6/addons-linter#31
Closed
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 terrorizer1980/addons-linter#35
Closed
@Z-byte-prog Z-byte-prog mentioned this pull request Jul 17, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 Z-byte-prog/docs#1243
Closed
@safiaminnn safiaminnn mentioned this pull request Jul 21, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 safiaminnn/juice-shop#5
Open
@YoYBaBy YoYBaBy mentioned this pull request Jul 23, 2024
[Snyk] Upgrade semver from 7.3.2 to 7.6.2 YoYBaBy/nodejs.org#274
Open
@koishichito koishichito mentioned this pull request Jul 24, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 koishichito/juice-shop#5
Open
@KobayashiMasaomi KobayashiMasaomi mentioned this pull request Jul 25, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 KobayashiMasaomi/juice-shop#10
Open
@q1blue q1blue mentioned this pull request Jul 28, 2024
[Snyk] Upgrade semver from 5.7.2 to 7.6.2 https-quantumblockchainai-atlassian-net/botframework-sdk#1
Open
@otmaneEH otmaneEH mentioned this pull request Jul 30, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 otmaneEH/docs#4
Open
@annkornienko annkornienko mentioned this pull request Jul 30, 2024
[Snyk] Upgrade semver from 7.3.5 to 7.6.2 Simpplr/serverless-plugin-include-dependencies#12
Closed
@wraithgar wraithgar mentioned this pull request Aug 20, 2025
speedup writeup #800
Closed
@jdmiranda jdmiranda mentioned this pull request Oct 4, 2025
Performance Optimization Opportunities: Caching, Memoization, and Allocation Reduction #814
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

1 more reviewer
@wraithgar wraithgar wraithgar approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@macno @wraithgar
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.