Excessing object wrapping.
See original GitHub issueI’m noticing with webpack v3 there’s a lot of this kind of generated code:
Object(__WEBPACK_IMPORTED_MODULE_3__module_resolve_filename_js__["a" /* default */])(foo)
What’s the reason for wrapping all references with Object()
and can this be disabled or optimized away to a single wrap?
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:15 (8 by maintainers)
Top Results From Across the Web
Wrapping bumper with several raised objects - Teckwrap
As soon as it is done, remove the excess film and the masking tape, then seal the edge with the hard part of...
Read more >How to Shrink Wrap Large Objects - YouTube
How to Shrink wrap large objects is a step by step how to video for educational purposes. The animated short video is fun...
Read more >Let's Talk Shop: Wrapping Unique Objects - GRAPHICS PRO
Over the years we've had some interesting objects come in to be wrapped. ... vinyl to the object and cut away any excess...
Read more >5 Ways to Wrap Cylindrical Gifts - wikiHow
1. Measure and cut the paper. When you are wrapping a cylinder-shaped gift, you can easily measure out the amount of paper using...
Read more >DIY: How to Wrap Odd-Shaped Gifts (UPDATED) | Zazzle Ideas
First, measure the width of the object you wish to wrap, add an inch to that measurement, and cut. Overlap the wrapping paper...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
The reason is to call the function with the correct this context:
The Object() is generated when calling a imported symbol directly. I omitted this in an older version, assuming nobody care about
this
in an exported function, but this breaks when exporting native functions likesetTimeout
with expected nothis
.Most of these are optimized away with the ModuleConcatenationPlugin.
A bit of history of this: (This started 1.5 years ago)
(0, a.b)()
for this, but this broken because of ASI when the previous line has no semicolon…a.b.bind(undefined)()
and alsoa.b.bind()()
butbind
is pretty slow.a.b.call(undefined)
as it’s a bit faster.__webpack_require__.i(a.b)()
with a identity functionObject(a.b)()
becauseObject
behaves like identity for functions and doesn’t require a custom function in the runtime.Here are up-to-date results:
Note:
bind
got faster in node 8,bind
is slow in firefox, most calls are faster in FF than in Chrome,Object()
is also a bit slow.Object()
is slower than aidentity
function, but 30ms for 1 million calls… who cares?this
is not used, or anarrow function
is used.@sokra I see, thanks for the clarification. Will land the
Object
call inlining today, so Chrome M63 and some future version of Node should haveObject(o.f)()
as fast asconst f = o.f; f()
.Wrote down some details here.