question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

proposal: revise usage of property getters

See original GitHub issue

Due 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:

  1. master branch: ~8s in total, ~4.8s for Javascript
  2. moving .buffer to actionPrint 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 grafik

changes from 2. without debounce buffer grafik

changes from 2. with debounce buffer grafik

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:8 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Tyriarcommented, Apr 23, 2018

@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:

interface IBufferSet {
  // Usages via the IBufferSet will not allow assignment
  readonly activeBuffer: IBuffer;
}

class BufferSet implements IBufferSet {
  public activeBuffer: IBuffer;
}

// Instead of
class BufferSet {
  private _activeBuffer: IBuffer;
  public get activeBuffer(): IBuffer { return this._activeBuffer}
}

Terminal.buffer is a little different here though as it’s exposing a property on buffers for convenience only. The workaround in https://github.com/xtermjs/xterm.js/pull/1399 is good.


What do you mean by additional debounce buffer?

0reactions
jerchcommented, Apr 26, 2018

Hmm interesting idea. I think only tests can tell if there is anything to save by an approach like this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Proposal: Semi-auto-properties with setters [topic has evolved ...
I have to update my previous post now, because this ever existing in getter and setter has problems. It could break existing code,...
Read more >
[Proposal] Property behaviors - Discussion - Swift Forums
The behavior declaration can explicitly provide metadata about the behavior, such as what container and value types it supports, what kinds of accessors ......
Read more >
Proposal: Storage for getters and setters - ESDiscuss.org
So here'swhat I propose: the getter gets a parameter which is the stored value; the setter's return value is set as value for...
Read more >
Property getters and setters - The Modern JavaScript Tutorial
Getters /setters can be used as wrappers over “real” property values to gain more control over operations with them. For instance, if we...
Read more >
PHP RFC: Property Accessors
Property accessors allow implementing custom behavior for reading or writing a property. PHP already provides this general functionality ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found