proposal: revise usage of property getters
See original GitHub issueDue to some performance tests for the new parser stuff I encountered the internally used property getters being a major bottleneck. Here are some numbers for ls -lh /usr/lib
on my ubuntu machine:
- master branch: ~8s in total, ~4.8s for Javascript
- moving
.buffer
toactionPrint
method (see #1399): ~6s in total, ~3.4s for Javascript
–> 1.5x as fast just by avoiding the .buffer
getter? What about all those other getters 😉
@Tyriar It seems the property accessors are not optimized by most JS engines, at least Firefox and Chrome show the same bad performance for them while a direct access via a public attribute is much faster. I am aware that getter/setter provide a nice way of encapsulation while being able to change the underlying implementation, but with such a huge performance impact I propose to at least revise their widespread usage in the core parts. Maybe the access could be be realized by attributes, that are handled especially careful.
Somewhat offtopic:
Btw with an additional debounce buffer in the demo app server script I was able to get ls -lh /usr/lib
with the changes in 2. down to under 3s in total. That is only 300% the time the native xterm needs for the same command - this is really amazing, congrats for getting the rendering part this fast!
Without the buffer the websocket eats much time itself sending single or two byte frames (thats the greyish thing in chrome summary pie). Not being a “bug” of xterm.js itself it still might be worth a note in the docs, if people are just copying the demo over to their apps.
Update: Fix timings and add some pics:
master branch
changes from 2. without debounce buffer
changes from 2. with debounce buffer
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:8 (8 by maintainers)
Top GitHub Comments
@jerch interesting 😮. One way we could remove getters and still keep many of the benefits is for properties that we’re just exposing readonly version of them we can have the interface property marked as
readonly
and just expose the variable:Terminal.buffer
is a little different here though as it’s exposing a property onbuffers
for convenience only. The workaround in https://github.com/xtermjs/xterm.js/pull/1399 is good.What do you mean by additional debounce buffer?
Hmm interesting idea. I think only tests can tell if there is anything to save by an approach like this.