when.js and Object.freeze

112 views
Skip to first unread message

Brian Cavalier

unread,
Oct 17, 2012, 9:37:56 PM10/17/12
to
when.js currently calls Object.freeze() on all promises it creates. The thinking is that something so basic as a promise should not be allowed to be tampered with.  Other promise libs, such as Q, freeze their promises for similar reasons.  Unfortunately, it turns out there's a rather horrendous performance penalty for accessing properties of frozen objects in v8.  This affects both node and chrome.  You can see it in action in this jsperf and also in these promise performance tests: results of when.js calling Object.freeze vs. results of when.js NOT calling Object.freeze

As of v1.5.1 when.js provides a way to turn off the calls to freeze() via a load-time configuration, but I'm wondering if we should just remove freeze() entirely until the v8 perf situation gets better.

So, the real question is, does anyone actually care if promises are frozen or not?  Regardless of the v8 situation, does freeze()ing them provide some benefit in your situation?  If so, or if not, I'd love to hear.

Thanks!
b

johlrogge

unread,
Oct 18, 2012, 8:11:26 AM10/18/12
to cuj...@googlegroups.com
I love the idea of freeze but I wouldn't lose any sleep if it was removed. So my +1 for removing it for the time being.

Brian Cavalier

unread,
Oct 19, 2012, 7:15:21 PM10/19/12
to cuj...@googlegroups.com
Cool thanks.  I'm in the same boat.  I agree the promises should be frozen, so the plan would be to reinstate Object.freeze once v8 gets its act together :)

Spain Train

unread,
Jan 21, 2014, 5:15:27 PM1/21/14
to cuj...@googlegroups.com

Brian Cavalier

unread,
Jan 21, 2014, 9:31:00 PM1/21/14
to cuj...@googlegroups.com
Ah, thanks for the heads up!  Any idea when that will land in a node or Chrome canary release?
Reply all
Reply to author
Forward
0 new messages