Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Makes patches optional #2543

Merged
merged 7 commits into from
Mar 29, 2021
Merged

Makes patches optional #2543

merged 7 commits into from
Mar 29, 2021

Conversation

arcanis
Copy link
Member

@arcanis arcanis commented Mar 1, 2021

What's the problem this PR addresses?
The builtin patches are currently problematic as they prevent users from using the latest versions of some dependencies (in particular TS), with no real workaround (#2514).

How did you fix it?
This diff implements a syntax making patches optional, and turns it on for the builtin compatibility patch. If such patches fail to cleanly apply, they'll simply fallback to the original sources rather than break. Users will then be able to temporarily enable the node_modules linker to circumvent the problem.

Why not just disable patches with nm linkers?

  • The compatibility patches are already noop under nm environments
  • Applying patches regardless of the settings makes installs more consistent
  • There are subtleties around the lockfile and the cache that would make that inconvenient for users that mix PnP and nm installs (which is a valid use case, for example when using PnP on CI and nm locally).

Checklist

  • I have set the packages that need to be released for my changes to be effective.
  • I will check that all automated PR checks pass before the PR gets reviewed.

// changeset. We need to open it for each patchfile (rather than only a
// single time) because it lets us easily rollback when hitting errors
// on optional patches (we just need to call `discardAndClose`).
const patchedPackage = new ZipFS(currentFile, {
Copy link
Member

Choose a reason for hiding this comment

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

Could you change this part and the initialCopy to be in-memory, then write the resulting buffer to disk for the returned ZipFS instance?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think I can, since we need to take snapshots in-between each patch. If I was to closeAndSave a memory zipFs, then we'd to already have in memory another one representing the last snapshot; this would be difficult unless we clone the memory zipFs somehow, which I don't know how to do efficiently.

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member Author

Choose a reason for hiding this comment

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

Oh I forgot getBufferAndClose 🤔 Still, it would require to keep the whole archive in memory, twice per package. I'm a bit worried it would be heavy (by contrast, by closing / opening, it only needs the archive listing)... given that the general case is to apply a single patch, I'd tend to first try the fs approach and switch only if we see a noticeable impact.

Copy link
Member

Choose a reason for hiding this comment

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

Can we at least profile both approaches and compare the time spent and the memory usage to make sure that we don't introduce a significant performance regression? Since compression is the slowest part of the fetch step, I'd prefer to avoid having to compress the archive for each patch file. I've also just realized that my changes still aren't optimal because they don't prevent compression (I have to pass level: 0 for that to happen).

Copy link
Member Author

@arcanis arcanis Mar 2, 2021

Choose a reason for hiding this comment

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

Sure, will check - I however expect the compression level to affect new writes, not the existing ones. With that in mind we can't disable compression, since it would require to go back and compress the affected files after all the patches have been applied - far too complex for a fringe use case (multiple patches on the same package).

Copy link
Member Author

Choose a reason for hiding this comment

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

For the record: 22s install time for TS code cache, vs 15s before.

.yarnrc.yml Outdated Show resolved Hide resolved
@arcanis
Copy link
Member Author

arcanis commented Mar 29, 2021

Going to merge it now; seems like the patch will break again with TS 4.3 Beta 🙁 In any case we'll likely have to release a 2.4.2 just for this.

@arcanis arcanis merged commit f09dc2f into master Mar 29, 2021
@arcanis arcanis deleted the mael/optional-patches branch March 29, 2021 16:03
milesrichardson added a commit to splitgraph/splitgraph.com that referenced this pull request Jul 6, 2021
Core problem is that `yarn berry`, when using `pnp` mode, requires
a patch to `typescript`. But we're using the `node-modules` linker.
Need to upgrade yarn I think

Tracking issues:
    - yarnpkg/berry#2935
    - yarnpkg/berry#2543
    - yarnpkg/berry#2711
milesrichardson added a commit to splitgraph/splitgraph.com that referenced this pull request Jul 7, 2021
Core problem is that `yarn berry`, when using `pnp` mode, requires
a patch to `typescript`. But we're using the `node-modules` linker.
Need to upgrade yarn I think

Tracking issues:
    - yarnpkg/berry#2935
    - yarnpkg/berry#2543
    - yarnpkg/berry#2711
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants