fix(core): fix #989, remove unuse code, use shorter name to reduce bundle size#990
fix(core): fix #989, remove unuse code, use shorter name to reduce bundle size#990mhevery merged 7 commits intoangular:masterfrom
Conversation
…duce bundle size
| */ | ||
|
|
||
| // issue #989, to reduce bundle size, use short name | ||
| export const a = Object.getOwnPropertyDescriptor; |
There was a problem hiding this comment.
there is no need to have a single char letters here. You can have long names, they will get renamed using uglify. Single letters are hard on readability.
There was a problem hiding this comment.
Thanks for pointing out this one, I have misunderstanding about uglfiyjs, I have changed the variable name to long names.
| export const k = 'true'; | ||
| export const l = 'false'; | ||
| export const m = '__zone_symbol__'; | ||
| export const n = 'function'; |
There was a problem hiding this comment.
i think typeof x == 'string is faster than typeof x == STRING_CONST. That is because in one case the jitter can create the check code which directly checks type to be string, in tho other case it has to generate a more complex code which could be actual type and than compare it to the constant. I would revert this.
There was a problem hiding this comment.
Got it, I have reverted all typeof x === parts.
| const ignoreProperties: IgnoreProperty[] = _global.__Zone_ignore_on_properties; | ||
| // for browsers that we can patch the descriptor: Chrome & Firefox | ||
| if (isBrowser) { | ||
| const w: any = window; |
There was a problem hiding this comment.
local vars get renamed. Calling it w makes it hard to read. Could we call it window and that way we don't have to change the code bellow? I know window = window would not work, but something like that?
There was a problem hiding this comment.
yes, you are right, I have changed the variable to internalWindow.
|
|
||
| performanceMeasure('Zone', 'Zone'); | ||
| const z: any = Zone.prototype; | ||
| z.w = z.wrap; |
There was a problem hiding this comment.
I would prefer that we don't pollute the Zone public API with these short names. I realized they are not part of .d.ts but they will show up in debugger.
How about this idea
Zone.current could be replaced with getZoneCurrent() which is declared in util file. The uglify will rename the getZoneCurrent to something short like x.
Zone.current.wrap(...) could be wrapWithCurrentZone(...)
and so on. What do you think?
There was a problem hiding this comment.
Yes, this is a better solution, I created wrapWithCurrentZone and scheduleMacroTaskWithCurrentZone helper method.
| z.si = z.scheduleMicroTask; | ||
| z.se = z.scheduleEventTask; | ||
| z.ct = z.cancelTask; | ||
| (Zone as any).l = Zone.__load_patch; |
There was a problem hiding this comment.
same thing here, helpers in util.ts can hide the long name without loosing readability
alfaproject
left a comment
There was a problem hiding this comment.
I don't think this is good for the maintainability of the project, and most of the things you changed will minify/compress just fine and with better results.
|
|
||
| Object.create = <any>function(obj: any, proto: any) { | ||
| if (typeof proto === OBJECT && !Object.isFrozen(proto)) { | ||
| // o is 'object' string |
There was a problem hiding this comment.
yes, I have reverted this one, thank you!
| * @suppress {undefinedVars,globalThis,missingRequire} | ||
| */ | ||
|
|
||
| // issue #989, to reduce bundle size, use short name |
There was a problem hiding this comment.
You shouldn't do the job of a compressor.
In fact, you are probably adding entropy.
P.S.: all of these extra imports/exports add up to browser parsing/interpreting time as well
There was a problem hiding this comment.
Yes, you are right, I have misunderstanding about uglifyjs, I have modified the PR.
e6eb346 to
d7ef237
Compare
|
awesome! thanks! |
fix #989.
remove unused code
move
getUserMediaandelectronrelated code to standalone files.use
shortervariable and function name to reduce bundle size.now the size of
zone.min.jswill be38510or38955bytes. (the size will change when I rebuild)add file size check logic in
travisbuild.change
func.applytofunc.callfor better performance.now I set a
limitationofzone.min.jsto40000bytes.@mhevery , please review the idea is ok or not. thank you!