Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize for large bundles with numerous globs #326

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

snipervld
Copy link

At the moment, Asset.ExpandGlobs{:.c#} doesn't cache results of provider.GetAllFiles("/"), so in the following example (simplified example - in the real app, this bundle contains different globs at different nested levels):

builder
    .Services
    .AddWebOptimizer(
        pipeline =>
        {
            //...
            pipeline.AddJavaScriptBundle(
                "bundle1",
                "js/*",
                "js/*",
                "js/*",
                "js/*",
                "js/*",
                "js/*");
            //...
        },
        options =>
        {
            options.EnableTagHelperBundling = false;
        });

Asset.ExpandGlobs will get all files 6 times. It can be a problem, if the virtual files hierarchy is huge.

This PR caches the results of provider.GetAllFiles("/") per provider into HttpContext.Items dictionary.

Also, this fixes the case when many complex bundles are located on the same page, e.g.:

...
<script src="~/bundle1"></script>
<script src="~/bundle2"></script>
<script src="~/bundle3"></script>
...

Each of them will reuse the cached file hierarchy if possible.

P.S. As you can see, I've tested this with EnableTagHelperBundling = false. ScriptTagHelper and LinkTagHelper call Asset.ExpandGlobs on each execution, which resulted in 5 seconds of rendering for just the script tags in my app, instead of something like ~0.1 seconds. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant