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

feat: cancellable scan during optimization #12225

Merged
merged 3 commits into from Feb 28, 2023
Merged

feat: cancellable scan during optimization #12225

merged 3 commits into from Feb 28, 2023

Conversation

patak-dev
Copy link
Member

Closes #11243

Co-authored-by: dominikg

Description

This is a rework of #11243 using esbuild added support for canceling builds.

I don't see this as a fix for #9986. If it helps, it is on hiding a race condition we should still work out.


What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

@stackblitz
Copy link

stackblitz bot commented Feb 27, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Collaborator

@benmccann benmccann left a comment

Choose a reason for hiding this comment

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

This looks pretty good to me!

I don't see this as a fix for #9986. If it helps, it is on hiding a race condition we should still work out.

Yeah, you're right, I realized that as well. This is just for the scan phase. We'd need to do the same thing for the actual optimization phase which is where #9986 is occurring

@@ -48,8 +48,11 @@ export const importsRE =
/(?<!\/\/.*)(?<=^|;|\*\/)\s*import(?!\s+type)(?:[\w*{}\n\r\t, ]+from)?\s*("[^"]+"|'[^']+')\s*(?=$|;|\/\/|\/\*)/gm

export async function scanImports(config: ResolvedConfig): Promise<{
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is the return type right here? It looks like its returning { cancel, result } and not Promise<{ cancel, result }>

Copy link
Member Author

Choose a reason for hiding this comment

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

I was following @dominikg's PR here. The esbuildContext is only available after waiting for other async operations. But I agree that from a consumer POV, it is better to avoid the double promise, vitejs/vite@5ff8d8b (#12225) avoids this at the expense of a bit more complexity inside scanImports

@patak-dev
Copy link
Member Author

I don't see this as a fix for #9986. If it helps, it is on hiding a race condition we should still work out.

Yeah, you're right, I realized that as well. This is just for the scan phase. We'd need to do the same thing for the actual optimization phase which is where #9986 is occurring

I'll check this in another PR. What I'm thinking though is that we could avoid naming all temporal folders in the same way. That is forcing us to be very careful about serializing optimizer runs. We can add a unique key per run, so it will be deps_temp_a3f4fa, and then #9986 is no longer possible.

@dominikg
Copy link
Contributor

I don't see this as a fix for #9986. If it helps, it is on hiding a race condition we should still work out.

Yeah, you're right, I realized that as well. This is just for the scan phase. We'd need to do the same thing for the actual optimization phase which is where #9986 is occurring

I'll check this in another PR. What I'm thinking though is that we could avoid naming all temporal folders in the same way. That is forcing us to be very careful about serializing optimizer runs. We can add a unique key per run, so it will be deps_temp_a3f4fa, and then #9986 is no longer possible.

We would need a way to clean up residue though. Even today sometimes temporary vite config bundle files remain on disk if the process terminates at the wrong point in time. It would be worse when the same was true for optimizer output.

@benmccann
Copy link
Collaborator

To clean up, we could delete anything beginning with deps_temp_ when starting the server

@dominikg
Copy link
Contributor

To clean up, we could delete anything beginning with deps_temp_ when starting the server

needs to ensure that there isn't another server currently having a go at it. Having 2 running on the same setup at the same time was something that came up lately
#12150

and with optimize on build and parallel builds it might apply there too.

benmccann
benmccann previously approved these changes Feb 28, 2023
@benmccann
Copy link
Collaborator

needs to ensure that there isn't another server currently having a go at it

one way to do it would be to check if the folder is more than 1 day old then it's safe to delete or something like that

Co-authored-by: Ben McCann <322311+benmccann@users.noreply.github.com>
@patak-dev patak-dev merged commit 1e1cd3b into main Feb 28, 2023
@patak-dev patak-dev deleted the fix/cancel-scan branch February 28, 2023 19:14
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.

None yet

3 participants