mirror of https://github.com/webpack/webpack.git
				
				
				
			Merge pull request #5312 from webpack/performance/aggressive-splitting
performance improvements and comments
This commit is contained in:
		
						commit
						2b0943f618
					
				|  | @ -39,6 +39,13 @@ class AggressiveSplittingPlugin { | |||
| 	apply(compiler) { | ||||
| 		compiler.plugin("this-compilation", (compilation) => { | ||||
| 			compilation.plugin("optimize-chunks-advanced", (chunks) => { | ||||
| 				// Precompute stuff
 | ||||
| 				const nameToModuleMap = new Map(); | ||||
| 				compilation.modules.forEach(m => { | ||||
| 					const name = identifierUtils.makePathsRelative(compiler.context, m.identifier(), compilation.cache); | ||||
| 					nameToModuleMap.set(name, m); | ||||
| 				}); | ||||
| 
 | ||||
| 				const savedSplits = compilation.records && compilation.records.aggressiveSplits || []; | ||||
| 				const usedSplits = compilation._aggressiveSplittingSplits ? | ||||
| 					savedSplits.concat(compilation._aggressiveSplittingSplits) : savedSplits; | ||||
|  | @ -48,21 +55,25 @@ class AggressiveSplittingPlugin { | |||
| 				// 1. try to restore to recorded splitting
 | ||||
| 				for(let j = 0; j < usedSplits.length; j++) { | ||||
| 					const splitData = usedSplits[j]; | ||||
| 					const selectedModules = splitData.modules.map(name => nameToModuleMap.get(name)); | ||||
| 
 | ||||
| 					// Does the modules exist at all?
 | ||||
| 					if(selectedModules.every(Boolean)) { | ||||
| 
 | ||||
| 						// Find all chunks containing all modules in the split
 | ||||
| 						for(let i = 0; i < chunks.length; i++) { | ||||
| 							const chunk = chunks[i]; | ||||
| 
 | ||||
| 							// Cheap check if chunk is suitable at all
 | ||||
| 							if(chunk.getNumberOfModules() < splitData.modules.length) | ||||
| 								continue; | ||||
| 
 | ||||
| 						const nameToModuleMap = new Map(); | ||||
| 						chunk.forEachModule(m => { | ||||
| 							const name = identifierUtils.makePathsRelative(compiler.context, m.identifier(), compilation.cache); | ||||
| 							nameToModuleMap.set(name, m); | ||||
| 						}); | ||||
| 							// Check if all modules are in the chunk
 | ||||
| 							if(selectedModules.every(m => chunk.containsModule(m))) { | ||||
| 
 | ||||
| 						const selectedModules = splitData.modules.map(name => nameToModuleMap.get(name)); | ||||
| 						if(selectedModules.every(Boolean)) { | ||||
| 								// Is chunk identical to the split or do we need to split it?
 | ||||
| 								if(chunk.getNumberOfModules() > splitData.modules.length) { | ||||
| 									// split the chunk into two parts
 | ||||
| 									const newChunk = compilation.addChunk(); | ||||
| 									selectedModules.forEach(moveModuleBetween(chunk, newChunk)); | ||||
| 									chunk.split(newChunk); | ||||
|  | @ -76,7 +87,7 @@ class AggressiveSplittingPlugin { | |||
| 									newChunk.origins = chunk.origins.map(copyWithReason); | ||||
| 									chunk.origins = chunk.origins.map(copyWithReason); | ||||
| 									return true; | ||||
| 							} else { | ||||
| 								} else { // chunk is identical to the split
 | ||||
| 									if(j < savedSplits.length) | ||||
| 										chunk._fromAggressiveSplittingIndex = j; | ||||
| 									chunk.name = null; | ||||
|  | @ -87,6 +98,8 @@ class AggressiveSplittingPlugin { | |||
| 							} | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
| 				// 2. for any other chunk which isn't splitted yet, split it
 | ||||
| 				for(let i = 0; i < chunks.length; i++) { | ||||
| 					const chunk = chunks[i]; | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue