Repository navigation
perf(content): skip image traversal without imports - #17547
Conversation
🦋 Changeset detectedLatest commit: 4a60e88 The changes in this PR will be included in the next version bump. This PR includes changesets to release 417 packages
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 |
| ): T { | ||
| return entry.assetImports?.length | ||
| ? updateImageReferencesInData(entry.data, entry.filePath, imageAssetMap) | ||
| : structuredClone(entry.data); |
There was a problem hiding this comment.
Don't think we should clone it, for perf reasons. If this is about people pushing into arrays, they shouldn't be doing that, but more importantly, people who know not to do that should not suffer performance penalties to save those who do not know, if that makes sense.
There was a problem hiding this comment.
@matthewp I guess some kind of cloning is necessary, because we don't want to expose raw immutable data, and resolved image references need to modify the entry before returning. And structuredClone was added on purpose to fix Map and Set handling in Traverse.map, which was used before. See: #16701
I can follow up with another PR that builds on this one and adds internal caching for cloned and traversed entries.
There was a problem hiding this comment.
Ah, I forgot about that one. Ok, in that case, I think it's fine for now. I definitely do not want to document that we clone, so if there's a way in the future to prevent it we are able to do so.
I'll come back to reviewing this PR later.
There was a problem hiding this comment.
Still haven't forgotten about this one, will review in the next few days, sorry for the wait.
This PR contains the following updates: | Package | Change | [Age](https://docs.renovatebot.com/merge-confidence/) | [Confidence](https://docs.renovatebot.com/merge-confidence/) | |---|---|---|---| | [astro](https://astro.build) ([source](https://github.com/withastro/astro/tree/HEAD/packages/astro)) | [`7.2.0` → `7.2.1`](https://renovatebot.com/diffs/npm/astro/7.2.0/7.2.1) |  |  | --- ### Release Notes <details> <summary>withastro/astro (astro)</summary> ### [`v7.2.1`](https://github.com/withastro/astro/blob/HEAD/packages/astro/CHANGELOG.md#721) [Compare Source](https://github.com/withastro/astro/compare/[email protected]@7.2.1) ##### Patch Changes - [#​17612](withastro/astro#17612) [`7133730`](withastro/astro@7133730) Thanks [@​thelazylamaGit](https://github.com/thelazylamaGit)! - Fixes CSS hot module replacement after navigating between pages with `ClientRouter` - [#​17628](withastro/astro#17628) [`4ada248`](withastro/astro@4ada248) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a CSP violation when using both `security.csp` and `experimental.clientPrerender` with `data-astro-prefetch` links. The dynamically injected `<script type="speculationrules">` now uses a static `"source": "document"` approach with a CSS selector, producing a deterministic payload that is hashed and included in the CSP `script-src` directive at build time. - [#​17605](withastro/astro#17605) [`89e4647`](withastro/astro@89e4647) Thanks [@​ashleigh-yeoman](https://github.com/ashleigh-yeoman)! - Fixes middleware HMR not responding to changes in imported modules. Previously, only direct edits to the middleware file would trigger a reload. - [#​17582](withastro/astro#17582) [`bd2c1a5`](withastro/astro@bd2c1a5) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a regression where content collection `reference()` fields silently accepted entry IDs that don't exist, such as an ID that doesn't match a loader's slugified version of it. Astro now logs an error for references that point to a missing entry after all loaders finish syncing. - [#​17661](withastro/astro#17661) [`97b0cc7`](withastro/astro@97b0cc7) Thanks [@​ArmandPhilippot](https://github.com/ArmandPhilippot)! - Improves Markdown options documentation with links to the Markdown guide and official processors. - [#​17349](withastro/astro#17349) [`4328c73`](withastro/astro@4328c73) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes an issue where requests handled by the dev prerender environment (e.g. `/_image` with `@astrojs/cloudflare`'s `prerenderEnvironment: 'node'`) returned a 500 when a prerendered catch-all route existed, because non-prerendered route modules were imported in an environment where their runtime-specific APIs are unavailable - [#​17603](withastro/astro#17603) [`722eed6`](withastro/astro@722eed6) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes `<video>` and `<audio>` elements being non-functional after navigating via view transitions (`<ClientRouter />`) - [#​17616](withastro/astro#17616) [`3a890d2`](withastro/astro@3a890d2) Thanks [@​lazerg](https://github.com/lazerg)! - Fixes `experimental.incrementalBuild` re-rendering unchanged routes that import more than one asset. The route's dependency hash depended on the order the assets finished building, so two builds of identical sources could produce different hashes. The hash is now based on the file name each asset resolves to. - [#​17547](withastro/astro#17547) [`fba468c`](withastro/astro@fba468c) Thanks [@​dmgawel](https://github.com/dmgawel)! - Improves `getCollection()` and `getEntry()` performance for entries without local image references - [#​17602](withastro/astro#17602) [`16e0d9d`](withastro/astro@16e0d9d) Thanks [@​astrobot-houston](https://github.com/astrobot-houston)! - Fixes a build error caused by hash collisions in generated content collection image import identifiers </details> --- ### Configuration 📅 **Schedule**: (UTC) - Branch creation - At any time (no schedule defined) - Automerge - At any time (no schedule defined) 🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied. ♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox. 🔕 **Ignore**: Close this PR and you won't be reminded about this update again. --- - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box --- This PR has been generated by [Mend Renovate CLI](https://github.com/renovatebot/renovate). <!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiI0NC4xNy4xIiwidXBkYXRlZEluVmVyIjoiNDQuMTcuMSIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->
Changes
getCollection()andgetEntry()now skip traversal whenassetImportsis empty, while still returning a freshstructuredClone.Related to #16297
Testing
Added tests covering the bypass, image resolution, and mutation isolation.
Tested on large collections:
assetImportsDocs
Internal optimisation change.