Reputation: 6749
I have to create and retain hundreds of thousands of objects for my app. I've noticed in Chrome that sometimes when I load the page, it will take longer than usual to create the objects even though I have done 0 code changes. Then, after the objects are created, the page will run slower than usual; often times the CPU profiler will either say it's GC or some random function using the majority of the CPU. Like I said, sometimes I'll refresh the page without any code changes at all and I won't see this behavior. The two go hand in hand: if the objects are created slowly for whatever reason, the page WILL run slowly and say it is a random function or GC.
In IE, the page runs as I'd expect it to every time.
You can't diagnose anything without seeing thousands of lines of code, but does anyone have any ideas for me? Why would Chrome exhibit that behavior? Any easy tweaks I could try? Thanks!
Upvotes: 1
Views: 1181
Reputation: 229281
One simple tip is this. I'm not sure if it applies without seeing your code. If you are creating your objects using this pattern:
function Foo() {
this.func1 = function () { ... };
this.func2 = function () { ... };
}
etc., then instead use this pattern:
function Foo() {
}
Foo.prototype.func1 = function () { ... };
Foo.prototype.func2 = function () { ... };
The latter ends up being much, much faster. I'm not sure about it being more memory efficient, but it's likely.
Upvotes: 1