Skip to content

Add entropy calculation - #115

Open
clelland wants to merge 1 commit into
mainfrom
entropy
Open

Add entropy calculation#115
clelland wants to merge 1 commit into
mainfrom
entropy

Conversation

@clelland

@clelland clelland commented Aug 31, 2023

Copy link
Copy Markdown
Collaborator

This adds a simple calculation of image entropy, defined as the number of bytes in the image resource, divided by the rendered size of the image. If an image fails to meet the entropy threshold, then it is excluded as an LCP candidate image.

Closes: #72, #86


Preview | Diff

This adds a simple calculation of image entropy, defined as the number of bytes
in the image resource, divided by the rendered size of the image. If an image
fails to meet the entropy threshold, then it is excluded as an LCP candidate
image.

Closes: #86
@clelland
clelland requested a review from yoavweiss August 31, 2023 16:46
@clelland

Copy link
Copy Markdown
Collaborator Author

Open question - should the threshold be left as implementation-defined? This calculation could be effectively skipped by setting it to 0, if an implementor wanted to ignore entropy.

@sefeng211

Copy link
Copy Markdown

Ian, is there anything prevent this from landing? I think we can start with 0.05 for now to make sure all implementations have the same value. If we want to allow implementations to ignore entropy, maybe we can specify this feature is optional rather than making entropy itself to be implementation-defined.

@clelland

@clelland

Copy link
Copy Markdown
Collaborator Author

I think that question was the only reason I hadn't landed it yet. I can add a word or two to make the step optional if the implementation doesn't want to consider entropy (if you think that's useful -- or else we can just make it part of the definition)

@sefeng211

Copy link
Copy Markdown

Maybe just part of the definition I think?

@sefeng211

Copy link
Copy Markdown

@clelland Ian, do you have data about how often an low entropy image is detected? Or how useful is this? Or any data related to how the threshold was picked? Thanks!

@mmocny

mmocny commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

The effective visual size algo already has a section to account for entropy, and a note about it.

Some of this patch seems higher quality, but perhaps no longer relevant.

I think there is desire to refactor the current algo to split out what is really about effective size vs "contentful" criteria like entropy.

CC @shaseley as well.

@mmocny mmocny self-assigned this Jul 7, 2026
@mmocny

mmocny commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This patch can no longer land as-is, but, I'll take a stab at figuring out if any of its wording is worth keeping. Otherwise, I will close.

In general, this section of the spec is likely to undergo more change, anyway.

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.

Very large transparent SVG should not count as LCP

3 participants