Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.

Conversation

@Cherry
Copy link
Contributor

@Cherry Cherry commented May 25, 2021

This re-implements the work from @groenlid in #143 (thanks @groenlid!), but fixes up the issues it caused with tests.

To solve the tests, I've split the mocks.ts into 2 separate mocks, one for the global scope, and one for the request scope. This way, we can mock the globals like __STATIC_CONTENT on the global scope as needed for tests to once again pass as expected.

Further info can be found in #143 as well as some brief benchmarks:

Before change:
100 iterations: Done. Mean kv response time is 16.61
1000 iterations: Done. Mean kv response time is 17.798

After change
100 iterations: Done. Mean kv response time is 6.62
1000 iterations: Done. Mean kv response time is 7.296

Closes #139

@Cherry Cherry requested a review from kristianfreeman May 25, 2021 23:49
@Cherry Cherry marked this pull request as ready for review May 25, 2021 23:49
@SukkaW
Copy link
Contributor

SukkaW commented May 26, 2021

If you have ever tested the changes in real world Cloudflare Workers Environment, you will notice that it will break a lot of things and cause inconsistent behaviors.

You really shouldn't try to modify the test to suit your changes.

@Cherry
Copy link
Contributor Author

Cherry commented May 26, 2021

You really shouldn't try to modify the test to suit your changes.

The tests were modified to support the new global scoping of __STATIC_CONTENT via the various mocks that are done to create an environment for "testing". Previously, index.ts didn't reference any globals like __STATIC_CONTENT until inside of a function scope, and thus the mocks were fine, but now with this being parsed in the global scope, the mocks (and more specifically when they run) needed to be modified to support this.

As far as I can see, there is no other way to implement this performance boost by only parsing it once without modifying the tests, as this change very intentionally moves these globals into the global scope, so that they're only parsed once.

If you have ever tested the changes in real world Cloudflare Workers Environment, you will notice that it will break a lot of things and cause inconsistent behaviors.

I'm interested to hear any more details here. I did test this with wrangler dev as well as published worker, and things were working just fine. Could you provide any more specific information?

@Cherry Cherry force-pushed the cherry/asset-manifest-parse branch from 068bdb0 to 490837a Compare May 26, 2021 19:44
@Cherry Cherry force-pushed the cherry/asset-manifest-parse branch from 490837a to bfd1a64 Compare May 28, 2021 14:52
@Cherry Cherry force-pushed the cherry/asset-manifest-parse branch from bfd1a64 to d9f2858 Compare May 28, 2021 14:53
@kristianfreeman
Copy link
Contributor

no update here @Cherry so I think we're good to merge!

@Cherry
Copy link
Contributor Author

Cherry commented Jun 2, 2021

no update here @Cherry so I think we're good to merge!

Will do! I'll do one final round of testing this week (I'm a little nervous about this one as per the comments here, even if I haven't found any issues myself) and then merge in a few days. 👍

@Cherry
Copy link
Contributor Author

Cherry commented Jun 3, 2021

I did some final testing of this with 2 different sites, both via wrangler dev and a staging publish to workers.dev, without any issues at all. Merging for now, and if any issues are found we can revisit.

@Cherry Cherry merged commit c5d5de0 into master Jun 3, 2021
@Cherry Cherry deleted the cherry/asset-manifest-parse branch June 3, 2021 14:23
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Only parse ASSET_MANIFEST once on isolate startup, not per-request

3 participants