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.

initTable is slow, can we lazily load parts as they're needed?

See original GitHub issue

On my fairly fast gaming desktop it’s over a frame:

image

It looks like initTable could be made so only load chunks of table as necessary, splitting it into 32 parts (66636/32=2048 codepoints) would probably make it have minimal impact on frames following a load.

https://github.com/xtermjs/xterm.js/blob/cb97ab35cb753f66e79a3b3eaa9442fbd3747c4d/src/CharWidth.ts#L126-L131

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:29 (29 by maintainers)

github_iconTop GitHub Comments

1reaction
jerchcommented, Nov 16, 2018

@skprabhanjan Another approach - programmatically walk the 0 and 2 width codepoints to fill the table. Instead of repeatingly doing the bisect and isWideBMP eval for every single codepoint from 0 to 65536 we can simply create the lookup table cheaper by this:

function iTableProgrammed() {
  table.fill(1);
  table[0] = opts.nul;
  // control chars
  for (let i = 1; i < 32; ++i) {
    table[i] = opts.control;
  }
  for (let i = 0x7f; i < 0xa0; ++i) {
    table[i] = opts.control;
  }
  // combining 0
  for (let r = 0; r < COMBINING_BMP.length; ++r) {
    for (let i = COMBINING_BMP[r][0]; i < COMBINING_BMP[r][1]; ++i) {
      table[i] = 0;
    }
  }
  // wide chars
  for (let i = 0x1100; i <= 0x115f; ++i) {
    table[i] = 2;
  }
  table[0x2329] = 2;
  table[0x232a] = 2;
  for (let i = 0x2e80; i <= 0xa4cf; ++i) {
    table[i] = 2;
  }
  table[0x303f] = 1;  // wrongly added in loop before
  for (let i = 0xac00; i <= 0xd7a3; ++i) {
    table[i] = 2;
  }
  for (let i = 0xac00; i <= 0xd7a3; ++i) {
    table[i] = 2;
  }
  for (let i = 0xf900; i <= 0xfaff; ++i) {
    table[i] = 2;
  }
  for (let i = 0xfe10; i <= 0xfe19; ++i) {
    table[i] = 2;
  }
  for (let i = 0xfe30; i <= 0xfe6f; ++i) {
    table[i] = 2;
  }
  for (let i = 0xff00; i <= 0xff60; ++i) {
    table[i] = 2;
  }
  for (let i = 0xffe0; i <= 0xffe6; ++i) {
    table[i] = 2;
  }
}
iTableProgrammed();

This lowers the creation cost down to 1.5 ms for the whole table and can be done during lib initialization. This coupled with the slightly more expensive 64k table and we have really nice speedup at initialization and during runtime. 😸

@Tyriar Mission accomplished?

Edit: With .subarray instead of the loops the above table creation runs in 0.2 ms, lol.

0reactions
jerchcommented, Nov 23, 2018

Fixed with #1789.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Lazy Loading: How It Decreases Load Time and Increases ...
Lazy loading reduces the time it takes for a web page to open because the browser only loads a fraction of the content...
Read more >
Use lazy loading to improve loading speed - web.dev
This post explains lazy loading and why you might want to lazy-load elements on your site.
Read more >
What is Lazy Loading | Lazy vs. Eager Loading
Lazy loading is the practice of delaying load or initialization of resources or objects until they're actually needed to improve performance and save...
Read more >
Effects of Too Much Lazy Loading on Web Performance
According to many studies, there are two main advantages that any developer can achieve by lazy loading. Reduced page load time (PLT): We...
Read more >
Lazy loading components and code splitting in Vue.js
Vue.js handles loading components lazily with routes, so on the DOM you can load components only when they are needed through routes.
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