Repository navigation
Skip invalidate_caches() call on Python dedicated snapshot path - #8253
Conversation
There was a problem hiding this comment.
Superseded by the review of
4d907bd2.
This review, of 549a312c
✅ Approved — This is a small, correctly guarded optimization: dedicated snapshots skip the call, all other paths behave as before, and a test covers the change. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
📋 Code Quality: ✅ LGTM
The call moved from mountWorkerFiles to loadPyodide and runs right after it, so the order is unchanged for workers with no snapshot and for baseline snapshots. The guards in snapshot.ts and python.ts agree, because LOADED_SNAPSHOT_TYPE comes from the loaded snapshot's settings.snapshotType. The extended subdirectory test covers the zip directory cache and imports of a worker file and a stdlib module.
📝 Documentation: ✅ LGTM
The new code comments match the current behaviour.
Reviewed commit: 549a312c
549a312 to
4d907bd
Compare
There was a problem hiding this comment.
Superseded by the review of
5a3e63f1.
This review, of 4d907bd2
✅ Approved — Dedicated snapshots skip the cache invalidation, every other path behaves as before, and a test covers the change. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The invalidateCaches call moved out of mountWorkerFiles and now runs right after it in loadPyodide, so the order is unchanged for workers with no snapshot and for baseline snapshots. Both guards skip the call only for dedicated snapshots. The test changes are consistent: in BUILD.bazel the workflow-entrypoint tests have different names and use explicit src overrides, sdk.wd-test binds SERVER to the Server entrypoint, and the new subdir/b.py is registered in subdirectory.wd-test.
⚡ Performance: ✅ LGTM
Skipping the cache invalidation keeps the import caches built from the user worker, including the zip directory cache, so they are not rebuilt after a dedicated snapshot restore.
📝 Documentation: ✅ LGTM
The new code comments match the current behaviour.
Reviewed commit: 4d907bd2
dom96
left a comment
There was a problem hiding this comment.
I remember the invalidate_cache logic being tricky and we had to add a bunch of these in the past in places that didn't have them. This change makes sense to me, but I think we should get @hoodmane's thoughts on this too.
I also wonder if we should be more cautious (because this has a chance of breaking worker loading) and introduce this change behind a compat flag (or maybe just an autogate so we can quickly roll this back if it breaks things).
I see. Sure, putting this under the compat flag or autogate sounds reasonable. I don't think this is a breaking change for 99.9% cases, but users can do anything in Python... |
4d907bd to
5a3e63f
Compare
There was a problem hiding this comment.
Superseded by the review of
8c241596.
This review, of 5a3e63f1
✅ Approved — The change now sits behind an opt-in compatibility flag, the default path still invalidates caches as before, and tests cover both cases. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
- Flag:
pythonDedicatedSnapshotKeepImportCaches @206uses the next free ordinal. It is read inmetadata.tsand declared inmetadata.d.ts. It reaches Python through the genericCOMPATIBILITY_FLAGSobject, so it needs no other wiring. - Default behaviour:
KEEP_RESTORED_IMPORT_CACHESis true only for a dedicated snapshot with the flag set. In every other caseinvalidateCachesruns inmaybeRestoreSnapshotand again aftermountWorkerFiles, as it did before.mountWorkerFileshas only one caller, so no other path loses the call that moved out of it. - Tests:
a.pychecks that the zip directory cache is the same object after a dedicated restore when the flag is on, and a different object when it is off. The workflow-entrypoint andsdktest changes match the new.wd-testfiles. A TODO explains why the tests were split.
⚡ Performance: ✅ LGTM
With the flag set, a dedicated snapshot keeps the import caches it recorded, including the zip directory cache, so they are not rebuilt at cold start. Nothing new runs on the per-request path.
📝 Documentation: ✅ LGTM
The comment on the new compatibility flag and the code comments match the behaviour.
Reviewed commit: 5a3e63f1
5a3e63f to
8c24159
Compare
There was a problem hiding this comment.
Superseded by the review of
d8c97881.
This review, of 8c241596
✅ Approved — The optimization is behind an opt-in compatibility flag that has no default enable date, so the default path still invalidates caches. The flag uses the next free ordinal, and tests cover both settings. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The only change since the last review is the new flag in compatibility-date.capnp.
- Ordinal:
@206is the next free ordinal, afterexposeSerializationTestClass @205. - Opt-in: The flag has an enable name and a disable name, and no default enable date. It stays opt-in, so the default path still calls
invalidateCaches. - Wiring: The generated
COMPATIBILITY_FLAGSkeypython_dedicated_snapshot_keep_import_cachesmatches the name read inmetadata.tsand declared inmetadata.d.ts. - Tests:
subdirectory-keep-import-caches.wd-testenables the flag, anda.pychecks the behaviour both with the flag on and with it off.
⚡ Performance: ✅ LGTM
With the flag set, a dedicated snapshot keeps the import caches it restored, so they are not rebuilt at cold start. Every other path still invalidates caches as before, and nothing new runs per request.
📝 Documentation: ✅ LGTM
The comment on the new flag and the code comments match the behaviour.
Reviewed commit: 8c241596
8c24159 to
d8c9788
Compare
There was a problem hiding this comment.
✅ Approved — The optimization is behind an opt-in compatibility flag that has no default enable date, so the default path still invalidates caches. The flag uses the next free ordinal, and tests cover both settings. No issues found.
The decision is advisory: this review is a comment and never approves, blocks or requests changes on the pull request.
✅ All checks passed
🔒 Security: ✅ LGTM
No security concerns.
📖 AGENTS.md: ✅ LGTM
No issues found.
📋 Code Quality: ✅ LGTM
The only change since the last review is the new flag in compatibility-date.capnp.
- Ordinal:
@206is the next free ordinal, afterexposeSerializationTestClass @205. - Opt-in: The flag has an enable name and a disable name, and no default enable date. It stays opt-in, so the default path still calls
invalidateCaches. - Wiring: The generated
COMPATIBILITY_FLAGSkeypython_dedicated_snapshot_keep_import_cachesmatches the name read inmetadata.tsand declared inmetadata.d.ts. - Tests:
subdirectory-keep-import-caches.wd-testenables the flag, anda.pychecks the behaviour both with the flag on and with it off.
⚡ Performance: ✅ LGTM
With the flag set, a dedicated snapshot keeps the import caches it restored, so they are not rebuilt at cold start. Every other path still invalidates caches as before, and nothing new runs per request.
📝 Documentation: ✅ LGTM
The comment on the new flag and the code comments match the behaviour.
Reviewed commit: d8c97881 — same changes as 8c241596, so this is that commit's review (no new review was run; line numbers are as of 8c241596)
One more micro-optimization for cold start, similar to #8208.
invalidate_cachesis used to clear up the Python importlib cache. This was used to clean up the cache that was populated from the baseline snapshot which is not a user worker. However, in dedicated snashot, the import cache is created from the user worker so we don't need to clean it up again.Hopefully we should be able to save another ~10ms of cold start time with this.