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.

[BUG] Slow generation performance

See original GitHub issue

🐛 Bug Report

We are generating an Excel file with lots of rows but minimal formatting. We’ve found that the writeBuffer() call will spend aggregated 20.85s in addStyleModel() and only 5s in addWorksheets().

One of the bottlenecks seem to be using the serialized XML as the key on this.index.style in _addStyle(). We tried passing an Int16Array into the method and keying it on ${style[0]},${style[1]},${style[2]},${style[3]},${style[4]},${style[5]} instead, which reduced it to 17.12s.

We also observed that the style objects for each cell were always a different object, so the weakmap was never used. Combined with removing the weakmap checks, the total aggregate time of addStyleModel() was reduced to 558ms.

Lib version: 4.2.1

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:3
  • Comments:5

github_iconTop GitHub Comments

3reactions
hfhchancommented, Apr 27, 2022

We reduced it to 2.76s by calling finalizeWorkbook() before calling writeBuffer:

class ExcelGenerator {
  private internStyle<T extends Partial<Excel.Style>>(internedStyles: Map<string, T>, style: T, type: number) {
    let buf = `${JSON.stringify(style)}${type}`;

    const internedStyle = internedStyles.get(buf);
    if (internedStyle) {
      return internedStyle;
    }

    const newInternedStyle = Object.freeze(Object.assign({}, style));
    internedStyles.set(buf, newInternedStyle);
    return newInternedStyle;
  }

  public finalizeWorkbook(workbook: Excel.Workbook) {
    const internedStyles = new Map<string, Partial<Excel.Style>>();
    workbook.worksheets.forEach(worksheet => {
      (worksheet as any)._rows.forEach((row: Excel.Row) => {
        (row as any)._cells.forEach((cell: Excel.Cell) => {
          cell.style = this.internStyle(internedStyles, cell.style, cell.type);
        });
      });
    });
  }
}
0reactions
SpectreWulfcommented, Nov 23, 2022

We reduced it to 2.76s by calling finalizeWorkbook() before calling writeBuffer:

class ExcelGenerator {
  private internStyle<T extends Partial<Excel.Style>>(internedStyles: Map<string, T>, style: T, type: number) {
    let buf = `${JSON.stringify(style)}${type}`;

    const internedStyle = internedStyles.get(buf);
    if (internedStyle) {
      return internedStyle;
    }

    const newInternedStyle = Object.freeze(Object.assign({}, style));
    internedStyles.set(buf, newInternedStyle);
    return newInternedStyle;
  }

  public finalizeWorkbook(workbook: Excel.Workbook) {
    const internedStyles = new Map<string, Partial<Excel.Style>>();
    workbook.worksheets.forEach(worksheet => {
      (worksheet as any)._rows.forEach((row: Excel.Row) => {
        (row as any)._cells.forEach((cell: Excel.Cell) => {
          cell.style = this.internStyle(internedStyles, cell.style, cell.type);
        });
      });
    });
  }
}

This literally cut down the writeBuffer() time in our project by nearly 50% (!)

Thanks a lot! ❤

Read more comments on GitHub >

github_iconTop Results From Across the Web

Super Slow? (poor performance due to GPU not being used ...
So, I am a new player, just bought them game and installed it, I start a new game and movement is like walking...
Read more >
massive performance issues since 22.04 upgrade
Bug Description. Hi, After upgrading to 22.04 i had to fight with massive performance issues. Browsers appeared to hang every other minute, ...
Read more >
Detecting and Fixing Performance Problems That Have Non ...
Abstract—Performance bugs are programming errors that slow down program execution. While existing techniques can detect various types of performance bugs, ...
Read more >
Meltdown fix can make some machines slower - Intel - BBC
Its own tests suggested performance slowdown could range from 2% to 14%. It said the impact of the patch, designed to prevent the...
Read more >
[MC-64223] Terrain generation causes very slow chunk loading
Confirmed. Category: Performance, World generation ... Bug - A problem which impairs or prevents the functions of the product.
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