microsoft / microsoft/monaco-editor

[Feature Request] Allow using SharedWorker instead of Worker (for TypeScript)

Open
#4,754 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature-request
Dominant language
JavaScript
Stars
46.8k
Forks
4.1k
Avg merge
17h 58m
Merged PRs (30d)
1

Description

Context
  • This issue is not a bug report. (please use a different template for reporting a bug)
  • This issue is not a duplicate of an existing issue. (please use the search to find existing issues)
Description

I'm developing an application where users typically have many tabs open, most of which contain one of more instances of Monaco editor with TypeScript content.

As each tab runs its own Worker for the TS language service, this means that each tab uses approx. 150MB of memory just for the Worker.
As this can place a heavy burden on users' machines and slow down the browser quite a bit, I'm wondering if there is currently a way to work around this. In my use case, all tabs are running on the same origin and using the same extra libs, therefore sharing one TS language service across them should conceptually be possible.

Some potential approaches that have crossed my mind, but may not be feasible:

  • Create a SharedWorker that imports the TS Worker code and just handles the back-and-forth message passing
  • Run the TS Worker as a SharedWorker (is this possible?) and create a custom Worker running in each tab that just proxies all messages back and forth between the tab and the SharedWorker
  • Start the original TS Worker inside a SharedWorker (a Worker belonging to the SharedWorker, so to say) and use a bit more proxying (tab <=> Worker for tab <=> SharedWorker <=> Worker of SharedWorker). Judging from my first tests, the Worker global doesn't seem to be available within a SharedWorker's context

So in essence, my main questions are:

  • How can I run the Worker as a SharedWorker?
  • How can I configure Monaco to create a SharedWorker instead of the regular Worker?
  • Would a change within the Monaco codebase be needed to accomplish this?

I'm greatful for any hints and opinions whether/how the points above could be accomplished, or any ideas that would work better :-)

Monaco Editor Playground Link

No response

Monaco Editor Playground Code

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue names no files, tests, or entry points. Start by locating Monaco's TypeScript worker configuration and reviewing the SharedWorker requirements described in the issue; done would mean a documented supported approach or a clearly scoped Monaco change that enables the requested sharing.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend, web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.