5

I am working with quite large volume of data.
Mechanism:
JavaScript is reading WebSQL database, then assembles data into Object that has tree structure.
Then applies to tree object knockout.js (makes elements observable) then data-binds and then applies Jquery Mobile UI at the end.

Whole process takes unacceptable amount of time.
I have already optimized algorithm that makes tree object out of data, also optimised conversion to observables mechanism by pushing items directly into ko.observable arrays and calling hasMutated only once. I am applying knockout.js IF bindings to not process invisible tree nodes in UI until parent is opened.

Performance here is key.
After inspecting page load in timeline in Chrome developer tools I have noticed that Garbage Collector is doing cleans on every concurrent call when I am building tree object.

Chrome timeline - we can see GC collecting items multiple times

Question: Is there a way to temporarily disable Chrome GC and then enable it again after I am done with page processing?

P.S I know I could add reference to part that gets collected, basically introduce object that dominates and prevents GC collection, but this would require substantial changes through the code, and I am not sure I could keep it long enough, and it is likely to introduce memory leak. Surely there must be better way

Matas Vaitkevicius
  • 58,075
  • 31
  • 238
  • 265
  • 1
    did you confirm the performance issue is on javascript, not DOM? You may comment out `//ko.applyBindgs(viewmodel);`, that skips all the DOM changes , and you can test pure javascript performance. – huocp Mar 31 '14 at 23:03
  • you cannot disable GC since its execution are manage independently on javascript, you can only force to execute it by developer tools – Martin Surynek May 06 '14 at 17:42
  • Duplicate of http://stackoverflow.com/questions/13950394/forcing-garbage-collection-in-google-chrome – Brett Green Apr 17 '15 at 15:24
  • @BrettGreen no, it's the opposite of that question, which talks about forcing GC, whereas this one wants to disable GC. – jmrk Mar 18 '17 at 13:56

1 Answers1

1

No, there is no way to disable the garbage collector. There cannot be, because what is Chrome supposed to do when more memory is requested but none is available?

(Also, the garbage collector is very fine-grained and complicated; your screenshot is a bit too small to be readable, but in all likelihood what you're seeing are small steps of incremental work to keep up with allocations, and/or "minor GC" cycles that only operate on the relatively small area of the heap where new allocations happen.)

If you want to reduce time spent in GC, then the primary way how to achieve that is to allocate fewer and/or smaller objects. Yes, that can mean changing your application's design so that objects are reused instead of being short-lived, or similar changes in strategy.

If you allocate a lot, you will see a lot of GC activity, there is just no way around that. This is true even in languages/runtimes that are not considered "garbage collected", e.g. in C/C++ using new/delete a lot also has a performance cost.

jmrk
  • 34,271
  • 7
  • 59
  • 74