Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Immer 10#1028

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mweststrate merged 52 commits intomainfromimmer-10
Apr 17, 2023
Merged

Immer 10#1028

mweststrate merged 52 commits intomainfromimmer-10
Apr 17, 2023

Conversation

@mweststrate
Copy link
Collaborator

@mweststratemweststrate commentedMar 23, 2023
edited
Loading

Release notes

Overall, there is a rough performance increase of 33% for Immer (and in some cases significantly higher), and the (non gzipped) bundle size has reduced from 16 to 11.5 KB, while the the minimal gzipped import of justproduce has remained roughly the same at 3.3 KB.

For more details, see#1015

Migration steps

  1. If you have anyenableES5() call, don't migrate
  2. When using getters/ setters icmw plain objects, calluseStrictShallowCopy(true) at startup
  3. Replace all default imports: Replaceimport produce from "immer" withimport {produce} from "immer"
  4. Replace all calls toenableAllPlugins() withenablePatches(); enableMapSet(); to be more specific and smoothen future migrations.
  5. If any producer returned a Promise, refactor it to leveragecreateDraft instead. Roughly:
constnewState=awaitproduce(oldState,recipe)// becomesconstdraft=createDraft(oldState)awaitrecipe(draft)constnewState=finishDraft(draft)

kshramtand others added16 commitsJuly 31, 2022 23:41
Patches generated by the current implementation do not follow the RFC method for removing an element from an array (https://www.rfc-editor.org/rfc/rfc6902#page-13) and cannot be used from other languages (e.g.,https://pypi.org/project/jsonpatch/).
@coveralls
Copy link

coveralls commentedMar 23, 2023
edited
Loading

Pull Request Test Coverage Report forBuild 4622958383

Warning: This coverage report may be inaccurate.

We've detected an issue with your CI configuration that might affect the accuracy of this pull request's coverage report.
To ensure accuracy in future PRs, please seethese guidelines.
A quick fix for this PR: rebase it; your next report should be accurate.

  • 79 of79(100.0%) changed or added relevant lines in10 files are covered.
  • 1 unchanged line in1 file lost coverage.
  • Overall coverage increased (+1.5%) to99.796%

Files with Coverage ReductionNew Missed Lines%
src/utils/errors.ts188.24%
TotalsCoverage Status
Change from baseBuild 4504340943:1.5%
Covered Lines:641
Relevant Lines:642

💛 -Coveralls

@markerikson
Copy link
Collaborator

Just ran a quick check on 9.0.16 vs 10.0.beta, using Vite 4.2.1 +source-map-explorer:

  • 9.0.16:immer/dist/immer.esm.mjs, 10.42KB
  • 10.0.0-beta.4:immer/dist/immer.mjs, 15.78KB

If I hand-inspect the Vite bundle output, I don'tsee anyNODE_ENV references left in there, which is what I would expect - they exist in the ESM artifact, but the minifier should get rid of those.

If it helps at all, I just manually copied and pasted the minified versions of 9.0.16 and 10.0.0-beta.4 out of Vite-built bundles, ran them through Prettier, and am attaching them as a zip - maybe it'll help show where the differences are:

immer-minified-prettified.zip

Per theMap/Set thing: FWIW, we reallydon't want people using theMap/Set support with RTK because of serialization issues, so at least in our case that is a size increase we don't benefit from. But, I do understand how that can cause confusion and annoyance onyour side. (My own preference would be that it still be opt-in somehow if possible.)

@mweststrate
Copy link
CollaboratorAuthor

mweststrate commentedApr 4, 2023 via email

Ah interesting! Is there a documentation section I can refer people back toif they report this in the future? RTK is probably the biggest packagedImmer provider, so if that isn't even supposed to be done in that case,happy to reconsider
On Mon, Apr 3, 2023 at 6:11 PM Mark Erikson ***@***.***> wrote: Just ran a quick check on 9.0.16 vs 10.0.beta, using Vite 4.2.1 + source-map-explorer: - 9.0.16: immer/dist/immer.esm.mjs, 10.42KB - 10.0.0-beta.4: immer/dist/immer.mjs, 15.78KB If I hand-inspect the Vite bundle output, I don't *see* any NODE_ENV references left in there, which is what I would expect - they exist in the ESM artifact, but the minifier should get rid of those. If it helps at all, I just manually copied and pasted the minified versions of 9.0.16 and 10.0.0-beta.4 out of Vite-built bundles, ran them through Prettier, and am attaching them as a zip - maybe it'll help show where the differences are: immer-minified-prettified.zip <https://github.com/immerjs/immer/files/11140726/immer-minified-prettified.zip> Per the Map/Set thing: FWIW, we really *don't* want people using the Map/Set support with RTK because of serialization issues, so at least in our case that is a size increase we don't benefit from. But, I do understand how that can cause confusion and annoyance on *your* side. (My own preference would be that it still be opt-in somehow if possible.) — Reply to this email directly, view it on GitHub <#1028 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAN4NBF56VRECVVNPETOLHTW7MADJANCNFSM6AAAAAAWFUJMLA> . You are receiving this because you authored the thread.Message ID: ***@***.***>

@markerikson
Copy link
Collaborator

Yeah, the two most immediate references are here:

We actually had an internal discussion aboutMap/Set usage again yesterday after seeing your comment, and concluded it's still not sufficiently worth it. Itis hypothetically possible to rework the Redux DevTools with one of the new "JSON superset" serialization libs, but it's fairly common for folks to want to persist state inlocalStorage (often using theredux-persist library), and that would run into serialization issues. There'd also be more nuance to try to explain in the docs, and it's simpler if we leave it at a blanket "Don't!" :)

@mweststrate
Copy link
CollaboratorAuthor

@markerikson I reverted the MapSet opt-in in immer@10.0.0-beta.6, mind doing a check if it solves the bundle size increase?

@markerikson
Copy link
Collaborator

@mweststrate yeah, I'll check on that tonight!

@markerikson
Copy link
Collaborator

markerikson commentedApr 6, 2023
edited
Loading

@mweststrate: Okay, 3 builds of the same RTKQ app, changing only the Immer version:

VersionBundle (min)Bundle (gzip)Sourcemapped file
9.0.16386.77 kB122.41 kB10.42 kB
10.0-beta.4392.30 kB123.74 kB15.78 kB
10.0-beta.6387.12 kB122.31 kB10.76 kB

I'm still generally surprised that 10.x isn'tsmaller than 9.x, given the changes.

@markerikson
Copy link
Collaborator

markerikson commentedApr 7, 2023
edited
Loading

@mweststrate : well, you got me hooked :)

I cloned theimmer-10 branch and did some poking around. I think there's a few things going on:

  • You're currently building the project with TSDX. That seems to be adding some polyfills, like_extends() (which you can see in the CJS dev build).
  • That in turn is partly becausetsconfig.json is set totarget: "ES6".

So, those are adding up to a bunch of dead bytes that aren't needed.

Unrelated to the bundle sizes, there's also issues with the current build output in this beta:

  • I know you've been flipping file names back and forth. Right now there's animmer.mjs bundle, but animmer.esm.js.map sourcemap file
  • The sourcemaps themselves seem broken and incorrect. If you try loading some of them intohttps://evanw.github.io/source-map-visualization/ , you'll see that variables and segments don't line up correctly, making them semi-useless

FWIW, Ijust switchedredux andredux-thunk over to usehttps://tsup.egoist.dev/ . It's basically like TSDX conceptually, except that it's based on ESBuild + Rollup (and it seems to actually bemaintained atm).

I just tried making a local branch that switches over totsup instead, and after 15-ish minutes I've got a decent part of the output bundles generating. More than that, I've got the minified files shrinking noticeably. Inbeta.6,immer.cjs.production.min.js is 16542b, and withtsup I've already got it down to 13680b. I also tried generating a minified.mjs artifact for comparison, and that's down to 12941b.

Some other notes here:

  • I see room for some byte shaving tricks. For example, I triedexport const getPrototypeOf = Object.getPrototypeOf and deleting theObject. in front of the uses, and that shaved off a few bytes because the variable name gets minified down to justE.
  • I'm 95% set on dropping UMD bundles for Redux 5.0 / RTK 2.0, especially since you can make a pre-built ESM bundle that should be importable in-browser. Might want to consider that here.
  • I'd say you can probably drop the Flow support too, really :)

Sooooo, with all that said:

If you're interested,I can try to do the rest of the TSDX ->tsup conversion, and file that as a PR against this branch.

Thoughts?

@mweststrate
Copy link
CollaboratorAuthor

@markerikson thanks for pointing out tsup! I was already wondering what was the modern bundling setup since tsdx went unmaintained, which was also the reason I didn't want to poke too much in the config. So happy to receive a PR! Please do leave the flow types, as they're useful inside Meta, so I try to keep them roughly up to date :)

@markerikson
Copy link
Collaborator

@mweststrate okay, sure! I'll try to put up a PR over the weekend.

@markerikson
Copy link
Collaborator

@mweststrate done! See#1032 .

Please let me know if you have any questions or would like me to tweak things further!

@mweststrate
Copy link
CollaboratorAuthor

mweststrate commentedApr 12, 2023 via email

Sorry had some PTO and now playing really hard catch-up! I'll try to goover it in the weekend :)
On Mon, Apr 10, 2023 at 5:34 PM Mark Erikson ***@***.***> wrote:@mweststrate <https://github.com/mweststrate> done! See#1032 <#1032> . Please let me know if you have any questions or would like me to tweak things further! — Reply to this email directly, view it on GitHub <#1028 (comment)>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAN4NBHGCON5TCPRRR2ELJLXAQR7JANCNFSM6AAAAAAWFUJMLA> . You are receiving this because you were mentioned.Message ID: ***@***.***>
markerikson reacted with thumbs up emoji

@mweststrate
Copy link
CollaboratorAuthor

@markerikson just publishedimmer@10.0.0-beta.7

@mweststratemweststrate merged commit2ef9a42 intomainApr 17, 2023
@github-actions
Copy link
Contributor

🎉 This PR is included in version 10.0.0 🎉

The release is available on:

Yoursemantic-release bot 📦🚀

hrsh7th reacted with hooray emoji

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Immer takes a long time to update the data.

5 participants

@mweststrate@coveralls@markerikson@hrsh7th

[8]ページ先頭

©2009-2025 Movatter.jp