Skip to content

feat: prerender & analyse in worker rather than subprocess to support Deno - #9919

Merged
Rich-Harris merged 3 commits into
sveltejs:masterfrom
fernandolguevara:fork-on-workers
May 16, 2023
Merged

Rich-Harris merged 3 commits into
sveltejs:masterfrom
fernandolguevara:fork-on-workers

Conversation

@fernandolguevara

@fernandolguevara fernandolguevara commented May 13, 2023 •

Copy link
Copy Markdown
Contributor

use workers instead of child_process

related:
denoland/deno#17248

@benmccann would you be able to review this PR?

@changeset-bot

changeset-bot Bot commented May 13, 2023 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 333e7ed

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sveltejs/kit Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@Rich-Harris Rich-Harris left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this LGTM! thank you. just had one small observation, inline.

I'm not sure I totally understand how this affects Deno though — it looks like child_process and worker_threads are both implemented. Is there some nuance I'm missing?

Comment thread packages/kit/src/utils/fork.js Resolved
@benmccann benmccann changed the title feat(fork): use workers feat: prerender in worker rather than subprocess to support Deno May 13, 2023
@benmccann

Copy link
Copy Markdown
Member

I'm not sure I totally understand how this affects Deno though — it looks like child_process and worker_threads are both implemented. Is there some nuance I'm missing?

It sounds to me like Deno implements child_process, but not communication between child and parent process and for that recommend using workers - or at least that's what I got from this article. @bartlomieju would you be able to confirm if that's correct?

@fernandolguevara fernandolguevara changed the title feat: prerender in worker rather than subprocess to support Deno feat: prerender & analyse in worker rather than subprocess to support Deno May 13, 2023
@bartlomieju

Copy link
Copy Markdown

Thanks for the ping @benmccann.

It sounds to me like Deno implements child_process, but not communication between child and parent process

That's true, we currently don't have support for the child_process.send() API. Unfortunately our polyfill for the worker_threads module is broken at the moment, but given that you have a need for it, we can prioritize fixing it and get it done next week. Does that sounds reasonable to you?

@benmccann

Copy link
Copy Markdown
Member

Thanks! Yeah, we can wait to merge this on our side then. I'm also fine going either the worker_threads or child_process.send() route if one is easier than the other

@bartlomieju

Copy link
Copy Markdown

Workers would definitely be easier - we just need to update once-working code. I'll prioritize this work over the next week and get back to you once it's released (I'll target to release in Deno v1.33.4 next week).

@ghost

ghost commented May 13, 2023

Copy link
Copy Markdown

iirc we have been using child_process to ensure resources are properly cleaned up (eg db connections). Is that still the case with worker?

@bartlomieju

Copy link
Copy Markdown

iirc we have been using child_process to ensure resources are properly cleaned up (eg db connections). Is that still the case with worker?

@dominikg I believe so - workers use separate OS threads, so once the worked is closed/terminated the resources will be released back to the OS.

@Rich-Harris

Copy link
Copy Markdown
Member

This code guarantees that everything is correctly shut down — if it wasn't, the tests would never complete:

// this code is here to make sure that we kill the process
setInterval(() => {
console.log('process is still alive');
}, 5000);

So given that the tests are passing I'm confident that it works correctly.

@pboguslawski

Copy link
Copy Markdown

Please take a look at #9989 - seems that using workers require also env cleanup.

teemingc added a commit that referenced this pull request Nov 18, 2026
Fixes "#17617"

Build workers unconditionally replaced the inherited FORCE_COLOR with
'1'. Consequently, setting NO_COLOR caused Node to warn about
conflicting settings during otherwise successful builds, and explicit
color-disable/depth settings were lost.

The forced-color default was introduced with improved diagnostics in
#16374. It still serves a purpose:
worker output does not otherwise retain terminal color detection.
Removing it entirely would regress those diagnostics.

Instead, only add the FORCE_COLOR default when the parent hasn't
disabled colors with a non-empty NO_COLOR, and pass everything the
parent sets through unchanged. An explicit FORCE_COLOR (including 0) is
preserved, and when the parent sets both variables the worker gets both,
so it resolves colors the same way the parent does. An empty NO_COLOR
counts as unset, matching Node and the NO_COLOR spec.

This central change covers route analysis, prerendering, and fallback
generation. It preserves environment inheritance from
#8777, worker_threads compatibility
from #9919, and the
cleanup/exit-handler behavior from
#17135. Regression coverage uses the
existing real-worker fixture rather than mocking worker construction.

- [Ported SvelteLab
reproduction](https://www.sveltelab.dev/#code=N4IgDghgxg1hDmBTAdAKwM4H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0HcNZJnr1wg9OS1g6eUh62AIDAWJ42BaeN7AZUGP1ZYw6YkPAaBYLgi71WmTVZluuQXIgQn0I2xQACRTiS-04ID5wgN1YDLoorxZG9WLRDD4xpEWJZWOWPacHCOIgFoUBygUVgANppAOegxFKyAA8QQPZCAAC6-pfZlJR0LzGP88gUNEMuEMZs1W7EHwmGKMs5KUnQijCIQOV8CcopEqSWtUsotL0scADc7Cq%2BryzACsEUSMIMJ6wbRtKdyEiSqUNt22rWHCE7BQkHmnzS-Abse5ghvHFKAccHmAkO%2BUiCELS8zp%2BHiCR9ggMABSk7K8paE2wis0pSzF8IZs6I9duIXACUbstyL2Awi3tu9jCQA).
Run build:no-color to reproduce the build warning with the pinned
release.

<!--
svelte-triage-bot:feedback-baseline:34a9e93738cd15903cc13bc4509c9647dd9d9238
-->

---------

Co-authored-by: svelte-triage-bot <[email protected]>
Co-authored-by: Tee Ming <[email protected]>

This branch was successfully deployed

1 active deployment
Preview – kit — 333e7edb Deployed May 13, 2023 by vercel[bot]
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.

5 participants