Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does using bundles in MVC cause increased memory usage

We have updated various sites to version MCV4 and simultaneously we exploited the ability to create Bundle with dll System.Web.Optimization. Everything works.

However, we have the following problem: when javascript is called the bundle of the application allocates about 50 MB RAM, without releasing it. The javascript included in the bundle have are in total about 2 Mb.

Note: We create Bundles in global asax, the event "Application_Start"

   protected virtual void Application_Start()
        {

        AreaRegistration.RegisterAllAreas();

        RegisterGlobalFilters(GlobalFilters.Filters);
        RegisterBundles(BundleTable.Bundles);
        RegisterRoutes(RouteTable.Routes);
    }



 protected virtual void RegisterBundles(BundleCollection bundles)
        {
        bundles.Add(new StyleBundle("~/content/all.css").Include(
                    "~/content/site.css"
                    ));

        bundles.Add(new StyleBundle("~/content/themes/base/base.all.css").Include(
                    "~/Content/themes/base/jquery-ui-1.8.23.custom.css",
                    "~/content/themes/base/kendo.common.css",
                    "~/content/themes/base/kendo.totalcom.css",
                    "~/Content/themes/base/jquery.contextmenu.css",
                    "~/content/themes/base/tipsy.css",
                    "~/content/themes/base/jquery.ibutton.css"
                    ));

        bundles.Add(new ScriptBundle("~/Scripts/all.js").Include(
                "~/Scripts/jquery-1.8.2.js",
                "~/Scripts/modernizr-1.7.js",
                "~/Scripts/jquery-ui-1.8.22.custom.js",
                "~/Scripts/jquery.validate.js",
                "~/Scripts/jquery.validate.unobtrusive.js",
                "~/Scripts/jquery.unobtrusive-ajax.js",
                "~/Scripts/conditional-validation.js",
                "~/Scripts/fileuploader.js",
                "~/Content/tiny_mce/jquery.tinymce.js",
                "~/Scripts/kendo.all.js",
                "~/Scripts/kendo.aspnetmvc.js",
                "~/Scripts/jquery.contextmenu.js",
                "~/Scripts/jquery.tipsy.js",
                "~/Scripts/jquery.checkradio.js",
                "~/Scripts/jquery.metadata.js",
                "~/Scripts/jquery.ibutton.js",
                "~/Scripts/jquery.easing.js",
                "~/Scripts/functions.js",
                "~/Scripts/Erp.js",
                "~/Scripts/Cms.js"
            ));
    }

The bundles are called in the masterpage

<%: Styles.Render("~/Content/all.css") %>
<%: Styles.Render("~/content/themes/base/base.all.css") %>
<%: Scripts.Render("~/Scripts/all.js") %>

EDIT: when the following line is executed an extra 50mb memory is used

<%:
Scripts.Render("~/Scripts/all.js")
 %>

Has anyone else has run into this problem? Any suggestions to reduce this memory consumption?

like image 734
Luca Dalsass Avatar asked Jun 25 '13 09:06

Luca Dalsass


People also ask

How does bundling increase performance in MVC?

To improve the performance of the application, ASP.NET MVC provides inbuilt feature to bundle multiple files into a single, file which in turn improves the page load performance because of fewer HTTP requests.

What is the advantage of bundling in MVC?

Bundling and Minification provide us a way to both reduce the number of requests needed to get JS and CSS resource files and reduce the size of the files themselves, thereby improving the responsiveness of our apps. They are nice little optimizations for our MVC apps that can improve performance and add responsiveness.

How does bundling work in MVC?

Creating a Bundle in MVC Bundling can create separate requests for CSS and JavaScript files. For example, if an application uses both the bootstrap and site CSS for UI design, we can create a common bundle for them. After Bundling, we need to register this bundle in the Application.

How does bundling use browser cache capability?

Busting Browser's Cache by Bundling As we upload the changes in the static resources such as CSS and JS files on the live server, the resources changes but it does not update on the Browser, because the Browser's cache resources are based on URLs automatically.


1 Answers

I recently had to deal with Bundles adding 200MB+ of memory to my IIS process when serving kendo.all.js (which is a staggering 5MB; the minified version is around 2MB), which is ridiculous. I plan on breaking that kendo file into several bundles and eliminating the controls I don't want, but I wanted to deal with that later.

In my case, I have both unminified and minified versions of the assets from the vendor. I don't need Bundles to minify anything. All I need it to do is emit the direct links to the unminified scripts when debug="true" and emit a link to the bundle of concatenated but preminified scripts when debug="false".

In my BundleConfig.cs, I had been using a ScriptBundle for my vendor files, which will attempt to minify, resulting in the cocked hat I've already mentioned. Using just plain old Bundle gives me the functionality I need without attempting to minify, and saving me a lot of memory. Sod off, ScriptBundle!

like image 153
moribvndvs Avatar answered Sep 26 '22 02:09

moribvndvs