Skip to content

sri: better algorithms for sri#4409

Closed
Uzlopak wants to merge 1 commit into
srifrom
sri-no-bs
Closed

sri: better algorithms for sri#4409
Uzlopak wants to merge 1 commit into
srifrom
sri-no-bs

Conversation

@Uzlopak
Copy link
Copy Markdown
Contributor

@Uzlopak Uzlopak commented Aug 12, 2025

I think we should deviate from the spec, as we can implement better and faster code than the algorithms defined in the spec. @annevk states, that:

"Generally we don't write algorithms in specifications with specific memory or performance targets in mind. The main goal is clarity. You can read more about this at https://infra.spec.whatwg.org/#algorithm-conformance."

The bytesMatch function is basically calculating the actualValue over and over. I addressed it here: w3c/webappsec-subresource-integrity#153

getStrongestMetadata can reuse the provided array. There is no point to create a new array and assign the items to it. Also there is no point in getting the index of the currentAlgorithm again and again. We just need to store the algorithmIndex in the strongest variable.

Also @annevk refers to infra conformance

Conformance requirements phrased as algorithms or specific steps may be implemented in any manner, so long as the end result is equivalent. (In particular, the algorithms are intended to be easy to follow, and not intended to be performant.)

So we just need to ensure, that the end result is equivalent to the end result of the spec.

If you agree on this, I would improve the comments in this PR, so that we have a better implementation of the sri

This relates to...

Rationale

Changes

Features

Bug Fixes

Breaking Changes and Deprecations

Status

@KhafraDev
Copy link
Copy Markdown
Member

So we just need to ensure, that the end result is equivalent to the end result of the spec.

No one is questioning our ability to implement the spec in our own manner, but even that wasn't done (see commented out test).

"Generally we don't write algorithms in specifications with specific memory or performance targets in mind. The main goal is clarity."

Yes, this is why we follow the spec. It makes it easier to maintain in the future, especially when other implementations deviate from it (like Chrome, with base64url) since we can float similar patches.

Since this is opt-in (only runs when passing an integrity option to RequestInit), conformance with the spec and other browsers is paramount to removing an array allocation or replacing a length check.

@Uzlopak
Copy link
Copy Markdown
Contributor Author

Uzlopak commented Aug 15, 2025

Yeah you are right. I hope the spec people will change some of these slow performance issues.

@Uzlopak Uzlopak closed this Aug 15, 2025
@Uzlopak Uzlopak deleted the sri-no-bs branch August 15, 2025 16:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants