How to Speed Up CPU-Intensive Tasks in an Obsidian Plugin? Workers Not Supported

Hi everyone! I’m developing an Obsidian plugin that acts like a static site generator (similar to Hugo), converting Markdown into HTML using custom templates.

Performance Issue

I’m running into a bottleneck with template rendering, which is CPU-intensive:

  • Same code:

    • ~5ms per page when run in a standalone Node.js environment
    • ~30–50ms per page when run inside Obsidian

Workers Not Supported

I tried using Worker / worker_threads to offload CPU-heavy logic, but Obsidian’s environment seems to block that:

Error: Failed to construct 'Worker': The V8 platform used by this instance of Node does not support creating Workers

Question

What are the best practices for performing CPU-intensive operations in an Obsidian plugin, especially when multithreading isn’t available?

What I’ve Tried

  • Breaking work into chunks with setTimeout() to yield back to the event loop
  • Reporting progress during long tasks
  • Simulating async processing — but no major performance improvement

:folded_hands: Looking for Advice

  • Any recommended strategies to speed up CPU-bound code in plugins?
  • Any alternatives to Workers for parallel or non-blocking execution?

Workers are supported, you just need to make sure that your build tool output’s the Browser compatible version and not the Node.js version.

Thanks for quick response, let me have a try with Browser Worker.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.