Skip to content

Optimize LuckyExcel xlsx preview conversion with Web Worker#766

Open
SpencerZhang wants to merge 1 commit into
kekingcn:masterfrom
SpencerZhang:luckyexcel-worker-preview
Open

Optimize LuckyExcel xlsx preview conversion with Web Worker#766
SpencerZhang wants to merge 1 commit into
kekingcn:masterfrom
SpencerZhang:luckyexcel-worker-preview

Conversation

@SpencerZhang

Copy link
Copy Markdown

Problem

When previewing large xlsx files, LuckyExcel performs Excel parsing and conversion on the main thread. For files with many shared strings, styles, or sheets, Chrome can report warnings such as:

[Violation] 'setTimeout' handler took xxxxms

The existing code wraps LuckyExcel.transformExcelToLuckyByUrl in setTimeout, but this only delays execution. The conversion still runs synchronously on the main thread and can block page interaction and loading UI updates.

There is also a debug log in luckyexcel.umd.js:

console.log(allFileOption, 'allFileOption')

For large files, allFileOption may contain huge structures such as sharedStrings, which makes DevTools logging slower and increases perceived loading cost.

Solution

This change moves LuckyExcel xlsx conversion into a Web Worker:

  • Add xlsx/luckyexcel-worker.js
  • Load luckyexcel.umd.js inside the worker with importScripts
  • Run LuckyExcel.transformExcelToLuckyByUrl in the worker
  • Send converted exportJson back to the main thread
  • Keep luckysheet.create on the main thread, since DOM rendering must remain there
  • Add fallback to the original main-thread conversion if Worker is unavailable or blocked
  • Comment out the large allFileOption debug log

Notes

This reduces main-thread blocking during Excel parsing/conversion. Very large files may still spend time in luckysheet.create, because rendering must happen on the main thread.

Verification

  • git diff --check
  • node --check server/src/main/resources/static/xlsx/luckyexcel-worker.js
  • mvn -s <temporary-aspose-settings> -U clean package -Dmaven.test.skip=true with JDK 21 generated server/target/kkFileView-5.0.0.tar.gz

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant