Skip to content

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

Merged
barjin merged 2 commits into
apify:masterfrom
r0stig:fix/raw-sitemap-hash
Nov 11, 2026
Merged

barjin merged 2 commits into
apify:masterfrom
r0stig:fix/raw-sitemap-hash

Conversation

@r0stig

@r0stig r0stig commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

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:45
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.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@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
@barjin
barjin self-requested a review November 11, 2026 12:57

@barjin barjin left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good catch, thank you @r0stig!

@barjin
barjin merged commit d2d2ad5 into apify:master Nov 11, 2026
14 checks passed
barjin pushed a commit that referenced this pull request Nov 11, 2026
)

Backport of #4381 to 3.x.

parseSitemap computes the raw://<sha256> 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 <url>, 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.

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.

2 participants