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 — replace `lru-cache` dependency by mbtools · Pull Request #697 · npm/node-semver

Conversation

@mbtools

@mbtools mbtools commented Apr 11, 2024

Copy link
Copy Markdown
Contributor

This change removes the dependency on the lru-cache package. It is replaced by a comparable, but much simpler class in this package. The cache is still set at max 1000 entries and works the same way as before.

Performance looks to be very similar. However, it needs a realistic test case that pushes the limits of the cache. I will leave it to more experts to judge.

References

#447, #448
#695
npm/cli#7350

Sorry, something went wrong.

Uh oh!

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

All reactions
@mbtools
chore: replace lru-cache dependency
3a74f20
@mbtools
mbtools requested a review from a team as a code owner April 11, 2024 19:38
@wraithgar

wraithgar commented Apr 11, 2024

Copy link
Copy Markdown
Contributor

Normally we try not to ask too much of contributors in the way of commits, and this is one of the reasons why we typically don't accept dependency change PRs. For those we'd prefer if the removal of lru-cache was a discrete deps: remove lru-cache commit so that it shows up in the changelog.

If it's not too much to ask can you make that package.json change a single commit w/ an appropriate commit message? Everything else you can keep in a second commit with a fix: prefix.

All reactions

Sorry, something went wrong.

Uh oh!

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

@wraithgar wraithgar changed the title chore: replace lru-cache dependency replace lru-cache dependency Apr 11, 2024
@wraithgar

wraithgar commented Apr 11, 2024

Copy link
Copy Markdown
Contributor

Our PR linter will pass if the PR subject or every commit has a valid conventional commit message. I've purposely made the PR subject a non-conventional one to reflect the fact that we intend to rebase-merge this PR with the deps and fix commits.

All reactions

Sorry, something went wrong.

Uh oh!

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

wraithgar
wraithgar reviewed Apr 11, 2024
View reviewed changes
Comment thread classes/lrucache.js Resolved

Uh oh!

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

wraithgar
wraithgar reviewed Apr 11, 2024
View reviewed changes
Comment thread classes/lrucache.js Resolved

Uh oh!

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

mbtools added 2 commits April 11, 2024 21:52
@mbtools
Move lrucache to internal, remove max default value
8b602dd
@mbtools
Revert package.json to the original state
cd5c652
@mbtools mbtools mentioned this pull request Apr 11, 2024
deps: remove lru-cache #698
Closed
@wraithgar

wraithgar commented Apr 11, 2024

Copy link
Copy Markdown
Contributor

Sorry for the confusion on the commit messages. If this is more than you want to do go ahead and get it all in here however you want and then we can get this PR green and we'll branch off of it and get the commits right.

All reactions

Sorry, something went wrong.

Uh oh!

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

ljharb
ljharb reviewed Apr 11, 2024
View reviewed changes
Comment thread internal/lrucache.js Resolved

Uh oh!

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

mbtools added 3 commits April 12, 2024 08:35
@mbtools
Replace generator & adjust snapshot
76201c7
@mbtools
Point range to internal
506a3b9
@mbtools
Remove deps
a4c2c76
@mbtools

mbtools commented Apr 12, 2024

Copy link
Copy Markdown
Contributor Author

Back to fully working. I will let you create a new PR with two commits as required. Thx!

All reactions

Sorry, something went wrong.

Uh oh!

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

@wraithgar

wraithgar commented Apr 12, 2024

Copy link
Copy Markdown
Contributor

Thank you! We'll let this sit for a bit for the community to weigh in, and we need some time to properly review it ourselves (we are in the middle of a large refactor in npm itself).

mbtools reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

lukekarrys
lukekarrys reviewed Apr 14, 2024
View reviewed changes

@lukekarrys lukekarrys left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm in favor of this PR and converting our lru-cache to an internal dependency.

If we do land this, I think we should remove any functionality that we aren't currently using in semver. Looking at the code that is only cache.set() and cache.get() (and set will call delete()). All my specific comments are about removing things. This is just my opinion and will let others weigh in first. So no need for anyone to make all these changes immediately 😄

Sorry, something went wrong.

Uh oh!

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

ljharb reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
Comment thread internal/lrucache.js Resolved

Uh oh!

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

Comment thread internal/lrucache.js Resolved

Uh oh!

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

Comment thread internal/lrucache.js Resolved

Uh oh!

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

Comment thread internal/lrucache.js Resolved

Uh oh!

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

Comment thread internal/lrucache.js Resolved

Uh oh!

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

lukekarrys
lukekarrys reviewed Apr 14, 2024
View reviewed changes
Comment thread test/internal/lrucache.js Resolved

Uh oh!

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

@wraithgar

wraithgar commented Apr 15, 2024

Copy link
Copy Markdown
Contributor

I'm in favor of the same @lukekarrys. I would like to see us get to a point where we're not testing semver's internal cache directly, but only as a side effect. That is, only testing it exactly how it's used during normal semver operations. Unit testing the module itself isn't that useful, all it does is show we HAVE a working cache, not that it's used by semver properly.

All reactions

Sorry, something went wrong.

Uh oh!

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

@lukekarrys lukekarrys changed the title replace lru-cache dependency feat: replace lru-cache dependency Apr 15, 2024
@wraithgar wraithgar changed the title feat: replace lru-cache dependency replace lru-cache dependency Apr 15, 2024
@wraithgar

wraithgar commented Apr 15, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

@lukekarrys the title of this PR is intentionally not conventional so that we remember to rebase it into two commits: one for the deps change and one for the feat

lukekarrys reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@mbtools

mbtools commented Apr 15, 2024

Copy link
Copy Markdown
Contributor Author

Sounds good. We can certainly reduce the cache functions to a minimum. I just had them in there to prove to myself that it's working like lru-cache.

If we're convinced the cache is fine, I suggest removing entries(), capacity(), the snapshots, and the max type check. But keep has() and size() so that the basic operations test still completes and we have 100% coverage.

The cache is transparent to the outside of range parse. Showing that semver uses it properly, is / should be visible only using runtime measurements. Not sure how you prefer to implement those.

All reactions

Sorry, something went wrong.

Uh oh!

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

@wraithgar

wraithgar commented Apr 16, 2024 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

The cache is transparent to the outside of range parse. Showing that semver uses it properly, is / should be visible only using runtime measurements. Not sure how you prefer to implement those.

Here's a proof of concept showing how we could assure that subsequent new Range instances get back the same range set.

const Semver = require('.')
const cached = Symbol('cached')
const r1 = new Semver.Range('1.0.0')
r1.set[0][cached] = true
const r2 = new Semver.Range('1.0.0')
console.log(r1.set[0][cached]) // Will be true
console.log(r2.set[0][cached]) // Will be true, showing it's cached.

We can test this all inside a t.test('cache') inside the range class tests.

All reactions

Sorry, something went wrong.

Uh oh!

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

@mbtools
Remove unnecessary cache methods & tests
3256e4b
@mbtools

mbtools commented Apr 17, 2024

Copy link
Copy Markdown
Contributor Author
  • Removed unnecessary cache methods & tests
  • Kept basic cache test to ensure 100% coverage
  • Added a test to range class as suggested
All reactions

Sorry, something went wrong.

Uh oh!

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

@wraithgar

wraithgar commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

Kept basic cache test to ensure 100% coverage

This still runs the risk that we have code in there we never use and don't need. If we aren't using the code from range we don't need to test it.

I think the cache size is the only thing left right? Can we loop through 1001 versions to test that the first one dropped out of the cache? Can the max size be hard set in lru-cache for now? There's no need to pass it in if we never set it to anything else.

All reactions

Sorry, something went wrong.

Uh oh!

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

@lukekarrys

lukekarrys commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

@wraithgar We still use a coverage map in this repo. I'm think that will require testing the cache directly to get full coverage, right?

All reactions

Sorry, something went wrong.

Uh oh!

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

@wraithgar

wraithgar commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

We can edit that file.

All reactions

Sorry, something went wrong.

Uh oh!

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

@wraithgar

wraithgar commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

Here's an example of how we did it in npm itself when we wanted to test a component of all the commands in a new test file:

https://github.com/npm/cli/blob/21b823edf7b3095ce1f53da7befda2b41296afe4/test/coverage-map.js

All reactions

Sorry, something went wrong.

Uh oh!

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

@mbtools
Hardcode max & minimal tests
91c69d7
@wraithgar

wraithgar commented Apr 17, 2024

Copy link
Copy Markdown
Contributor

I think that we should fix the tests but also not block this PR on "perfect" code. I'm good w/ this as-is (pending an actual review of the code at this point). We can clean it up on our own time.

mbtools reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@wraithgar wraithgar mentioned this pull request Apr 24, 2024
Dedupe LRU-Cache Dependency npm/cli#7350
Closed
@wraithgar

wraithgar commented Apr 24, 2024

Copy link
Copy Markdown
Contributor

We have not forgotten about this PR. The big npm display layer refactor is almost done and then we can come back to things like this PR.

mbtools reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

@H4ad H4ad mentioned this pull request Apr 24, 2024
chore!: bump lru-cache to 10.x & increase node engine #695
Closed
@wraithgar wraithgar mentioned this pull request May 1, 2024
replace lru-cache dependency #704
Merged
@wraithgar

wraithgar commented May 1, 2024

Copy link
Copy Markdown
Contributor

#704

All reactions

Sorry, something went wrong.

Uh oh!

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

@wraithgar wraithgar closed this May 1, 2024
@mbtools
mbtools deleted the lru branch May 28, 2024 18:36
@tommy-mitchell tommy-mitchell mentioned this pull request Oct 4, 2026
Replace lru-cache with internal implementation npm/hosted-git-info#343
Open
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

3 more reviewers
@wraithgar wraithgar wraithgar left review comments
@ljharb ljharb ljharb left review comments
@lukekarrys lukekarrys lukekarrys left review comments
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.

4 participants

@mbtools @wraithgar @lukekarrys @ljharb
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.