Open Bug 1385120 Opened 7 years ago Updated 2 years ago

Speedometer Ember benchmark spends a lot of time in toString().

Categories

(Core :: JavaScript Engine: JIT, defect, P2)

defect

Tracking

()

Tracking Status
firefox57 --- wontfix

People

(Reporter: sstangl, Unassigned)

References

Details

(Keywords: perf)

Profile here: https://perfht.ml/2w4g2x9 Running the Speedometer Ember benchmark, there is an Ion-heavy section that lasts for about 700ms. Within that section, we spend about 230ms just in the self-hosted toString(). toString() is mostly called in the context of the EmberJS function addObserverForContentKey(), reproduced below: > function addObserverForContentKey(content, keyName, proxy, idx, loc) { > while (--loc >= idx) { > var item = _emberRuntimeMixinsArray.objectAt(content, loc); > if (item) { > _emberMetalDebug.assert('When using @each to observe the array ' + content + ', the array must return an object', typeof item === 'object'); > _emberMetalObserver._addBeforeObserver(item, keyName, proxy, 'contentKeyWillChange'); > _emberMetalObserver.addObserver(item, keyName, proxy, >'contentKeyDidChange'); > } > } > } Note that the toString() call obviously happens in the context of a debug statement -- and that it's unfortunately converting an entire array to a String. Then it discards all that work. The length of content begins at 1, then increases linearly to 100, at which point it remains at length 100 and gets converted to a string 10,000 times per benchmark iteration. 1) We should probably report this to Ember. They could avoid doing the Array.prototype.join() and toString() by just having assert() take a callback. 2) Since this is occurring in Ion, it's possible that we could observe that the toString() and join() are not effectful, inline assert(), and reorder that code into the taken branch.
Blocks: QF-EmberJS
Also, the string built is just "[object Object],[object Object],[object Object],[object Object]," with "[object Object]," repeated 100 times.
Keywords: perf
Priority: -- → P2
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.