Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
2 tasks done
sumbricht opened this issue Nov 16, 2024 · 0 comments
Open
2 tasks done
Labels
feature-request Request for new features or functionality

Comments

@sumbricht
Copy link

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

@sumbricht sumbricht added the feature-request Request for new features or functionality label Nov 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

1 participant