-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Fix v8 Deopt in ModuleGraph due to wrong map #16829
Copy link
Copy link
Closed
Description
ModuleGraph.js causes a v8 deoptimization here:
Lines 136 to 147 in b7fc4d8
| */ | |
| _getModuleGraphModule(module) { | |
| let mgm = this._moduleMap.get(module); | |
| if (mgm === undefined) { | |
| mgm = new ModuleGraphModule(); | |
| this._moduleMap.set(module, mgm); | |
| } | |
| return mgm; | |
| } | |
| /** | |
| * @param {Dependency} dependency the dependency |
Isolate Log File Snippet
LoadIC,0x6551df9bde,16223580,563,20,1,P,0x01ad7455adf9,_getModuleGraphModule,,
code-deopt,16223649,640,0x1dc8d5a8320,-1,3848,deopt-eager,<C:\\Users\\selarkin\\Code\\webpack\\lib\\ModuleGraph.js:138:18>,wrong map
This is because freeze() method is introducing a new property to the ModuleGraph instance (this._cacheStage) after its already been initialized causing a Map transition and a "wrong map" deoptimization, preventing inline caching.
Below shows the v8 Map of the object changing into Polymorphic caused by freeze() and causing a IC miss:
First Map Shape: Initialization
Map Transition: freeze()
Initializing this_cacheStage in the constructor will fix this problem:
class ModuleGraph {
constructor() {
/** @type {WeakMap<Dependency, ModuleGraphConnection>} */
this._dependencyMap = new WeakMap();
/** @type {Map<Module, ModuleGraphModule>} */
this._moduleMap = new Map();
/** @type {WeakMap<any, Object>} */
this._metaMap = new WeakMap();
/** @type {WeakTupleMap<any[], any>} */
this._cache = undefined;
/** @type {Map<Module, WeakTupleMap<any, any>>} */
this._moduleMemCaches = undefined;
/** @type {string} */
this._cacheStage = undefined;
}
Reactions are currently unavailable

