Skip to content

fix(utils): hash raw sitemap content once per source, not per url - #4382

Open
r0stig wants to merge 2 commits into
apify:3.xfrom
r0stig:fix/raw-sitemap-hash-3.x
Open

r0stig wants to merge 2 commits into
apify:3.xfrom
r0stig:fix/raw-sitemap-hash-3.x

Conversation

@r0stig

@r0stig r0stig commented Nov 11, 2026

Copy link
Copy Markdown

Backport of #4381 to 3.x.

parseSitemap computes the raw:// originSitemapUrl inside the per-entry loop. For a raw source (Sitemap.fromXmlString(), or parseSitemap with { type: 'raw' }), it hashes the whole document again for every , so parsing costs O(urls × size).

We hit this with a real 4.2 MB sitemap with 22k URLs: parsing it from a string took ~42 s of CPU, versus ~0.3 s when crawlee fetches the same sitemap by URL. With the hash computed once per source, parsing the string takes ~0.2 s. The output is unchanged, since the value is identical for every entry of a source.

I've used AI to create this fix and generate the above text, but manually checked both code and texts.

r0stig and others added 2 commits November 11, 2026 06:51
parseSitemap built the `raw://<sha256>` originSitemapUrl inside the per-entry
loop, so for a raw source (Sitemap.fromXmlString, or parseSitemap with
`{ type: 'raw' }`) the whole document was hashed again for every <url>. The
cost was O(urls x size): a 4.2 MB sitemap with 22k URLs took ~42 s of CPU to
parse, versus ~0.2 s with the hash computed once per source.

Backport of the same fix on master.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions github-actions Bot added the t-tooling Issues with this label are in the ownership of the tooling team. label Nov 11, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

t-tooling Issues with this label are in the ownership of the tooling team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant