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

disable debug names in production builds #2780

Merged
merged 6 commits into from
Feb 9, 2021

Conversation

iChenLei
Copy link
Member

@iChenLei iChenLei commented Feb 4, 2021

Code change checklist

  • Added/updated unit tests
  • Updated /docs. For new functionality, at least API.md should be updated
  • Verified that there is no significant performance drop (npm run perf)

Updated /docs. For new functionality, at least API.md should be updated
👆 Need add it in official document ?

PR Background

reopen pr for #2748

Sumaary

Why not just add __DEV__ for getNextId()

this.keysAtom_ = createAtom(__DEV__ ? `${this.name_}.keys()` : "ObservableMap.keys()")  
 // 👆  e.g. why do this?

getNextId() is default debugnames gen util, and most time we will create new Atom, ObservableValue with name constructor params, so it also create many cancatenated string and string in JS Heap.(more details -> #2737

Run simple benchmark

import { observable } from 'mobx';

const HugeRootMobx = {};
for (let i  = 0; i < 100000; i++) {  👈🏻   // Yeah, One hundred thousand loop
 HugeRootMobx[i] = observable({ val: i });
}

window.mobxTest = HugeRootMobx;

Test on microsoft edge 87

This is JS Heap compare between different logic process.

2021-02-04 20 22 37
If we only deal with getNextId(), not optimized enough .

@mweststrate Need your code review, maybe I missing something. Thank you, sir 😄

@changeset-bot
Copy link

changeset-bot bot commented Feb 4, 2021

🦋 Changeset detected

Latest commit: 9b00a94

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
mobx Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

Copy link
Member

@mweststrate mweststrate left a comment

Choose a reason for hiding this comment

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

Thanks for looking into this. Looks awesome! Small request for changes as I think the mapid_ can probably be dropped entirely (or it is used somewhere, and in that case I'm not sure the change is safe)

@@ -88,7 +88,7 @@ export class ComputedValue<T> implements IObservable, IComputedValue<T>, IDeriva
lastAccessedBy_ = 0
lowestObserverState_ = IDerivationState_.UP_TO_DATE_
unboundDepsCount_ = 0
mapid_ = "#" + getNextId()
mapid_ = __DEV__ ? "#" + getNextId() : "#"
Copy link
Member

Choose a reason for hiding this comment

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

Looking at this one, it seems that mapid_ is used nowhere. Feel free to drop it entirely if that still passes the test

Copy link
Member Author

@iChenLei iChenLei Feb 6, 2021

Choose a reason for hiding this comment

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

If we delete mapid_ directly, The Unit Tests will be failed.

  1. keep it
  2. delete it and jest --updateSnapshot

Choice which one ? Sir.

@@ -57,15 +57,15 @@ export class Reaction implements IDerivation, IReactionPublic {
diffValue_ = 0
runId_ = 0
unboundDepsCount_ = 0
mapid_ = "#" + getNextId()
mapid_ = __DEV__ ? "#" + getNextId() : "#"
Copy link
Member

Choose a reason for hiding this comment

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

Same (probably the IDerivation interface needs to adapted as well)

packages/mobx/src/types/observablearray.ts Outdated Show resolved Hide resolved
@mweststrate
Copy link
Member

mweststrate commented Feb 6, 2021 via email

Copy link
Member

@mweststrate mweststrate left a comment

Choose a reason for hiding this comment

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

Looking great! Thanks for making these changes. As a really nit you might want to mention in the changelog that it will reduce memory usage of MobX in production builds, which is why some projects might be interested in upgrading :)

@mweststrate
Copy link
Member

Fun, _mapid was already unused since 2016 :) 6bf6da9

@iChenLei
Copy link
Member Author

iChenLei commented Feb 8, 2021

Fun, _mapid was already unused since 2016 :) 6bf6da9

That's funny, I was a sophomore college student in 2016, after 5 years I delete it. hah O(∩_∩)O~~

@iChenLei
Copy link
Member Author

iChenLei commented Feb 8, 2021

Looking great! Thanks for making these changes. As a really nit you might want to mention in the changelog that it will reduce memory usage of MobX in production builds, which is why some projects might be interested in upgrading :)

So you means add reduce memory usage info to changset ? Sir

@iChenLei
Copy link
Member Author

iChenLei commented Feb 8, 2021

Sir, I think I should do the same work for mobx4and5 branch. I will create anthor new pull request for it.

@danielkcz
Copy link
Contributor

danielkcz commented Feb 8, 2021

Sir, I think I should do the same work for mobx4and5 branch. I will create anthor new pull request for it.

Publishing older versions has to be done manually. I don't think this change can be classified as "critical bugfix". It's not worth the hassle imo and as Michel said, people might be at least motivated to upgrade to V6 which is our goal here.

@iChenLei
Copy link
Member Author

iChenLei commented Feb 8, 2021

Publishing older versions has to be done manually. I don't think this change can be classified as "critical bugfix". It's not worth the hassle imo and as Michel said, people might be at least motivated to upgrade to V6 which is our goal here.

Ok , I got it. 😄

@mweststrate
Copy link
Member

@iChenLei yes that was about the changeset indeed :)

@danielkcz
Copy link
Contributor

@iChenLei Perhaps be more explicit in the changeset and mention the removal of mapid_ specifically in case someone was crazy enough to use that for something.

@danielkcz
Copy link
Contributor

Thanks, let's merge.

@danielkcz danielkcz merged commit 9b195b1 into mobxjs:main Feb 9, 2021
@github-actions github-actions bot mentioned this pull request Feb 9, 2021
@urugator
Copy link
Collaborator

urugator commented Feb 12, 2021

Is it an intention to pass __DEV__ ? dynamic : static to every createAtom/new ObservableValue invocation instead of just ignoring the passed value inside Atom constructor?
I am asking because I think you have missed few places and also you do ignore name in ComputedValue constructor (as opposed to Atom/ObservableValue).

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.

4 participants