14

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?

Tommy
  • 39,592
  • 10
  • 90
  • 121
Luca Dalsass
  • 141
  • 1
  • 5
  • 1
    I have same issue http://stackoverflow.com/questions/24280851/why-scripts-render-invoke-jsminify-process/24341774?noredirect=1#comment37641657_24341774 – Mediator Jun 22 '14 at 06:46
  • How is your application deployed? Is it on a single server, or are you using a service like azure that uses a distributed cache? Also, what version of MVC web optimization are you using? – Jack Sep 12 '14 at 17:57
  • @Jack Version 1.1 - Single server, no azure. In production we use a web garden but I see this issue on my local system where there is only 1 w3wp.exe process – theycallmemorty Sep 12 '14 at 18:00
  • @theycallmemorty Oh ok, I thought it might be related to problems with a distributed cache or multiple threads. – Jack Sep 12 '14 at 18:42
  • @theycallmemorty, what version of the web optimization framework are you using? – Dave Alperovich Sep 12 '14 at 22:37
  • also, are you running in debug mode? your problem is common on servers running debug mode. The number 45MB+ is also common, it is about the size of optimization dll – Dave Alperovich Sep 12 '14 at 23:23
  • 1
    @DaveA problem is prevalent in release mode and debug mode - Using System.Web.Optimization version 1.1. – theycallmemorty Sep 15 '14 at 13:52
  • this problem was common. I would suggest upgrading to 1.3 – Dave Alperovich Sep 15 '14 at 14:08
  • @DaveA - What is the best way to determine the latest version? http://aspnetoptimization.codeplex.com/ seems to say 1.1.3 is the latest. – theycallmemorty Sep 17 '14 at 17:36
  • My bad. I meant 1.1.3. here's the official page https://www.nuget.org/packages/microsoft.aspnet.web.optimization/ – Dave Alperovich Sep 17 '14 at 17:41
  • Have you checked whether the bundling works using your browser's developer tools or any monitoring tool such as [Firebug](http://getfirebug.com/network). Besides, have you checked your Web.config file that compilation tag is set to false (``) so that bundling and minification will be enabled, or else you can add `BundleTable.EnableOptimizations = true;` to your `RegisterBundles` method to enable it. – oardic Sep 18 '14 at 21:20
  • Yes bundling is functioning correctly. – theycallmemorty Sep 19 '14 at 14:22

2 Answers2

5

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!

moribvndvs
  • 42,191
  • 11
  • 135
  • 149
  • How did you find out the memory usage of the bundles? I'm having similar problems, and I think Bundling might be the culprit, but I want to be sure. – Escobar5 Apr 25 '17 at 17:32
  • @Escobar5 At the time, I had mostly client script changes and it was the only server-side change. I noticed that the output of the bundles was severely mangled, so I reverted the change and the memory issue went away. I only looked into ScriptBundle vs Bundle enough to note the additional minification I didn't need, so I tried it with just Bundle and good enough. – moribvndvs Apr 25 '17 at 17:46
  • Thanks, will try that. – Escobar5 Apr 25 '17 at 18:06
  • You are my hero! – Schoof Jul 05 '18 at 13:34
  • I had the same thing with kendoui.all in my bundle, but my bundle also included several other large-ish libs. It caused an additional 450MB(!) of memory usage - right when Scrips.Render was called (found by watching diag. tools) Some seemed to be cleaned up after by GC, some not. EnableOptimizations on or off didn't matter. I ended up simply putting the old script tags back in and deleting bundle. With Web.Optimizations having not changed since 2014, I think we are dinosaurs. .Net Core does it differently, and many/most ppl seem to be moving to bundle in the design/build phase w. task runners – C.List Oct 27 '18 at 10:33
0

Can you please enable optimization

public static void RegisterBundles(BundleCollection bundles)
{
    // your bundling goes here

    BundleTable.EnableOptimizations = true;
}
Prashant Sarvaiya
  • 364
  • 1
  • 3
  • 14