<h2 dir="auto">Feature request</h2>





<p dir="auto"><strong>What is the expected behavior?</strong><br>
I need some webpack internals to use a <code class="notranslate">Promise</code> <strong>ponyfill</strong> instead of the global <code class="notranslate">Promise</code>.</p>
<p dir="auto"><strong>What is motivation or use case for adding/changing the behavior?</strong><br>
I'm bundling a web app that runs on 3rd party websites and I <strong>must not</strong> pollute their global namespace with polyfills.</p>
<p dir="auto"><strong>How should this be implemented in your opinion?</strong><br>
No idea, but I guess <code class="notranslate">Promise</code> is the only thing that needs a polyfill for IE11.</p>
<p dir="auto"><strong>Are you willing to work on this yourself?</strong><br>
yes</p>
<p dir="auto"><strong>Do you want to request a <em>feature</em> or report a <em>bug</em>?</strong><br>
I want to report a performance bug.</p>


<p dir="auto"><strong>What is the current behavior?</strong><br>
In projects with a lot of chunks, a lot of time is spent on <code class="notranslate">RemoveParentModulesPlugin</code>.</p>
<p dir="auto">The original report (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="216717731" data-permission-text="Title is private" data-url="https://github.com/angular/angular-cli/issues/5618" data-hovercard-type="issue" data-hovercard-url="/angular/angular-cli/issues/5618/hovercard?comment_id=354973859&amp;comment_type=issue_comment" href="https://github.com/angular/angular-cli/issues/5618#issuecomment-354973859">angular/angular-cli#5618 (comment)</a>) detailed a 1h build time for a non-production (no uglify etc) build.</p>
<p dir="auto">The project uses Angular CLI and contains around ~2700 source files. This project has <a href="https://github.com/angular/angular-cli/files/1599960/ng-build.log">376 chunks</a>.</p>
<p dir="auto">A similar sized project (<a href="https://github.com/filipesilva/angular-cli-test-repo">https://github.com/filipesilva/angular-cli-test-repo</a>) takes only a few minutes to build using the same options.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>



<p dir="auto">The project is closed source so I do not have a source, but the owner is available for some remote debugging (<a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="216717731" data-permission-text="Title is private" data-url="https://github.com/angular/angular-cli/issues/5618" data-hovercard-type="issue" data-hovercard-url="/angular/angular-cli/issues/5618/hovercard?comment_id=355033864&amp;comment_type=issue_comment" href="https://github.com/angular/angular-cli/issues/5618#issuecomment-355033864">angular/angular-cli#5618 (comment)</a>).</p>
<p dir="auto">He provided CPU profiles for the first ~10m with node 8.4.0 (<a href="https://github.com/angular/angular-cli/files/1600687/CPU-20180103T195000.cpuprofile.zip">here</a>) and with node 9.3.0 (<a href="https://github.com/angular/angular-cli/files/1606383/CPU-20180105T160658.cpuprofile.zip">here</a>).</p>
<p dir="auto">Both profiles show the majority of time being spent in <code class="notranslate">RemoveParentModulesPlugin</code>, specifically within the <code class="notranslate">hasModule</code> function. Also see the "Other information" bit at the end for a comparison with Webpack 4.</p>
<p dir="auto"><strong>What is the expected behavior?</strong><br>
<code class="notranslate">RemoveParentModulesPlugin</code> is optimized to allow having a lot of chunks without a big performance hit.</p>
<p dir="auto"><strong>Please mention other relevant information such as the browser version, Node.js version, webpack version and Operating System.</strong></p>
<p dir="auto">Node.js 8.4.0, Webpack 3.10.0. Unknown browser/OS.</p>
<p dir="auto"><strong>Other information.</strong></p>
<p dir="auto">I've been looking at Webpack 4 and thought maybe it could help since there are a lot of performance improvements there. The plugin in question has suffered some changes:</p>
<ul dir="auto">
<li>in <code class="notranslate">webpack@3.10.0</code>: <a href="https://github.com/webpack/webpack/blob/b545b519b2024e3f8be3041385bd326bf5d24449/lib/optimize/RemoveParentModulesPlugin.js">https://github.com/webpack/webpack/blob/b545b519b2024e3f8be3041385bd326bf5d24449/lib/optimize/RemoveParentModulesPlugin.js</a></li>
<li>in <code class="notranslate">webpack@4.0.0-alpha.3</code>: <a href="https://github.com/webpack/webpack/blob/9334fd8547831ded7f11e05319616a72ea0b4698/lib/optimize/RemoveParentModulesPlugin.js">https://github.com/webpack/webpack/blob/9334fd8547831ded7f11e05319616a72ea0b4698/lib/optimize/RemoveParentModulesPlugin.js</a></li>
</ul>
<p dir="auto">It looks like there's a fair bit of optimizations changes there. But I'm not sure if the bottleneck has changed.</p>
<p dir="auto">There's two places where time is being spent on the CPU profile:</p>
<ul dir="auto">
<li>a <code class="notranslate">has</code> call inside the <code class="notranslate">hasModule</code> function:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/4172079/34612357-52195fb0-f221-11e7-9af3-435cdfaab77f.png"><img src="https://user-images.githubusercontent.com/4172079/34612357-52195fb0-f221-11e7-9af3-435cdfaab77f.png" alt="image" style="max-width: 100%;"></a></li>
<li>a <code class="notranslate">filter</code> call inside the <code class="notranslate">hasModule</code> function:<br>
<a target="_blank" rel="noopener noreferrer nofollow" href="https://user-images.githubusercontent.com/4172079/34612366-61c554b4-f221-11e7-8c22-e4aa27a57744.png"><img src="https://user-images.githubusercontent.com/4172079/34612366-61c554b4-f221-11e7-8c22-e4aa27a57744.png" alt="image" style="max-width: 100%;"></a></li>
</ul>
<p dir="auto">This function hasn't changed though so I don't think it would speed up in this case.</p>
<p dir="auto">/cc <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/pleerock/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/pleerock">@pleerock</a> <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/TheLarkInn/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/TheLarkInn">@TheLarkInn</a></p>