Skip to content
Advertisement

NodeJS: Would App Run Faster if Freeze Objects?

Most of my objects/functions do not change. Would the application run faster if I freeze most of the objects via Object.freeze(object)? Or will it make no difference at all?

Advertisement

Answer

Freezing (and sealing) causes a signficant performance hit instead of a gain across various browsers. Just take a look at some of the jsperf benchmarks.

EDIT: Here‘s the relevant issue for v8.

EDIT2: The linked issue was fixed as of Dec 10, 2014. Frozen objects don’t have any performance hit according to the fix.

Optimize Object.seal and Object.preventExtensions

They both now run fast (due to utilizing transitions instead of always creating new maps) and sealed or non-extensible objects can stay in fast mode after transitioning.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement