[SVG] Put SVG document resources in a separate `MemoryCache` partition [chromium/src : main]

2 views
Skip to first unread message

Divyansh Mangal (Gerrit)

unread,
Sep 10, 2025, 3:57:25 PM (9 days ago) Sep 10
to Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Fredrik Söderquist, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Divyansh Mangal added 18 comments

Commit Message
Line 7, Patchset 18:[SVG] Introduce Page level cache identifier for `MemoryCache` for
SVG resources
Fredrik Söderquist . resolved

How about something more along the lines of:
> Put SVG document resources in a separate MemoryCache partition

and then expand on that in the non-title part?

Divyansh Mangal

Done

Line 18, Patchset 18:When an external SVG resource is updated, the cached version
persists. Even reloading the page does not reflect the updated
Fredrik Söderquist . resolved

"...no new request is made"

Divyansh Mangal

Done

Line 37, Patchset 18:identifier. The unique Id is genereted using
Fredrik Söderquist . resolved

typo

Divyansh Mangal

Done

Line 51, Patchset 18:
Change-Id: I6521e438713a36e491b841ac7b265b247f4b751f
Fredrik Söderquist . resolved

Bug#?

Divyansh Mangal

Done

File third_party/blink/renderer/core/page/page.cc
Line 590, Patchset 14: String(BrowsingContextGroupToken().ToString()));
Kurt Catti-Schmidt . unresolved

Does this need to be wrapped in a `String`?

Divyansh Mangal

Yes, because `BrowsingContextGroupToken().ToString()` returns `std::string` and there was no implicit conversion between `String` and `std::string`.

Fredrik Söderquist

Maybe we could add a prefix to this identifier to make it a bit more "discoverable" - something like `"svg-resources:<token-string>"` perhaps?

Divyansh Mangal

I have hardcoded the string currently, but I believe we generally create a corresponding string somewhere else?

File third_party/blink/renderer/core/svg/svg_resource_document_cache.h
Line 74, Patchset 18: String svg_cache_identifier_;
Fredrik Söderquist . resolved

This can be dropped (quite obvious from the class name).

Divyansh Mangal

Done

Line 62, Patchset 18: const String& GetSVGCacheIdentifier() const { return svg_cache_identifier_; }
Fredrik Söderquist . resolved

Redundant

Divyansh Mangal

Done

Line 60, Patchset 18: void AddStrongReference(SVGDocumentResource* resource);
Fredrik Söderquist . resolved

`AddResource`

Divyansh Mangal

Done

Line 73, Patchset 13: HeapLinkedHashSet<Member<SVGDocumentResource>> strong_references_;
Kurt Catti-Schmidt . resolved

Does this need to be a `HeapLinkedHashSet` vs just a `HeapHashMap`? Looks like the only real difference is that `HeapLinkedHashSet` maintains the order of insertion, but is that necessary?

Divyansh Mangal

`SVGResourceDocumentCache` will no longer be a cache, it will be a Tracker sort of thing (this will be subsequent renaming task corresponding to that) to keep track of the strong references of fetched SVG resources. So, we definitely no longer need a `HeapHashMap`. We need a data structure that can maintain a list of references effectively.

Among the data structures, I picked `HeapLinkedHashSet` because `MemoryCache` also uses the same to store strong references. Granted, in `MemoryCache` there is some logic corresponding to LRU and that's why `LinkedHashSet` makes sense there, we currently don't have any need for LRU logic here but in the future, it may arise so picking this data structure seemed ok to me. Other than this I had option for `HeapVector` but did not had any strong reason to pick that up.

Kurt Catti-Schmidt

In general, you want to use the most performant data structure at any given time. So if you need LRU in the future, you can implement and test it separately in the future and know the exact cost of a given data structure.

`HeapVector` would have a higher CPU + memory cache rate (due to sequential access) and less memory overhead, but you do lookups on `strong_references_` via `Contains`, and perform `erase`, both of which are O(N) for vectors. So a `HeapHashMap` will be a better choice here, as it won't have the additional linked list to maintain that `HeapLinkedHashSet` does.

Divyansh Mangal

I think you are right in that case, since I am using `Contains` or `erase` like functions `HeapHashMap` might be better. I guess I was worried about what Key should be taken, but I can take what we were earlier using anyway, @f...@opera.com, do you also think `HeapHashMap` is better here?

Fredrik Söderquist

I would say `HeapHashSet`, but yes, no need for a linked set that I can see. I'd also call this field something else than `strong_references_` - perhaps `tracked_resources_`?

Divyansh Mangal

I have used `HeapHashSet` as per this discussion and renamed the variable.

File third_party/blink/renderer/core/svg/svg_resource_document_cache.cc
Line 73, Patchset 18: if (resource) {
Fredrik Söderquist . resolved

We shouldn't allow nulls to be added to the set in the first place. (And this is making different assumptions than the other iterations.)

Divyansh Mangal

Done

Line 98, Patchset 18: for (const auto& resource : to_remove) {
strong_references_.erase(resource);
}
Fredrik Söderquist . resolved

`HashSet` has a `RemoveAll()`.

Divyansh Mangal

Done

Line 125, Patchset 18: const bool all_strong_references_are_observed = std::ranges::all_of(
Fredrik Söderquist . resolved
```suggestion
const bool all_resources_are_observed = std::ranges::all_of(
```
Divyansh Mangal

Done

Line 161, Patchset 18: if (strong_references_.Contains(resource)) {
return;
}

strong_references_.AppendOrMoveToLast(resource);
Fredrik Söderquist . resolved

This could just be a single `insert()` (assuming we go with a `HashSet`).

Divyansh Mangal

Done

Line 170, Patchset 18: for (const auto& resource : strong_references_) {
if (resource->GetContent() == content) {
return true;
}
}

return false;
Fredrik Söderquist . resolved

`any_of()`?

Divyansh Mangal

Done

File third_party/blink/renderer/core/svg/svg_use_element.cc
Line 651, Patchset 18: if (RuntimeEnabledFeatures::SVGPageLevelCacheIdentifierEnabled() &&
notified_target_observer_) {
return;
}
Fredrik Söderquist . unresolved

This looks like a bodge. This needs to be explained much better (this isn't even mentioned in the commit message). The naming of this field is also poor.

Divyansh Mangal

@f...@opera.com I agree on the ambiguity of this variable, let me try to explain why it was needed:

Consider your html has two <use> element both referencing the same resource. When first <use> fetches the resource and completion happens it will call [1] and notify itself. Then when the second <use> fetches the resources and completion happens it will notify all observers that are observing this resource. So it notifies, first <use> again and itself. This resulted in the first <use> element being notified twice which was not needed (and the DCHECK() at L:665 gets hit).

This behaviour was observed during the testing of WPT [2]

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/loader/resource/svg_document_resource.cc;drc=845d2024791ea649a25c4074bf25263b1f648ff9;l=106.

[2]
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/svg/struct/reftests/use-external-resource-with-revalidation.tentative.html?q=use-external-resource-with-revalidation.tentative.html

I wanted to use the active status of `pending_event_` to do the check instead but was not sure if that's a good fix given the DCHECK at L:665

File third_party/blink/renderer/platform/loader/fetch/memory_cache.cc
Line 446, Patchset 18: ResourceMap* resources = resource_maps_it->value.Get();
for (auto resource_iter = resources->begin();
resource_iter != resources->end(); resource_iter = resources->begin()) {
DCHECK(resource_iter.Get());
DCHECK(resource_iter->value.Get());
DCHECK(resource_iter->value->GetResource());
Resource* resource = resource_iter->value->GetResource();
DCHECK(resource);
RemoveInternal(resources, resource_iter);
}

resource_maps_.erase(resource_maps_it);
Fredrik Söderquist . resolved

This is the same as in `EvictResources()`. Could we factor out that bit instead an dreuse?

Divyansh Mangal

Done

File third_party/blink/renderer/platform/loader/fetch/resource_fetcher.cc
Line 985, Patchset 18: const String cache_identifier =
RuntimeEnabledFeatures::SVGPageLevelCacheIdentifierEnabled() &&
!params.GetSVGCacheIdentifier().empty()
? params.GetSVGCacheIdentifier()
: GetCacheIdentifier(
params.GetResourceRequest().Url(),
params.GetResourceRequest().GetSkipServiceWorker());
Fredrik Söderquist . unresolved

Rather than putting more "gunk" into `FetchParameters`, I think we could get this identifier via the `FetchContext` (and use `factory.GetType()` to limit those calls).

Also, I think we could put this logic in an overload of `GetCacheIdentifier()`.

Divyansh Mangal

I added the setter and getter in `FetchContext` and removed the corresponding from `FetchParameters`. The overloaded is also introduced in the new PatchSet.

File third_party/blink/renderer/platform/runtime_enabled_features.json5
Line 4746, Patchset 18: name: "SVGPageLevelCacheIdentifier",
Fredrik Söderquist . unresolved

Isn't more like "SvgDocumentResourcesInMemoryCache"(Partition)?

Divyansh Mangal

I have updated it to `PartitionSvgDocumentResourcesInMemoryCache`

Open in Gerrit

Related details

Attention is currently required from:
  • Fredrik Söderquist
  • Kurt Catti-Schmidt
  • Sejal Anand
  • Vinay Singh
  • Virali Purbey
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I6521e438713a36e491b841ac7b265b247f4b751f
Gerrit-Change-Number: 6807690
Gerrit-PatchSet: 23
Gerrit-Owner: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
Gerrit-Reviewer: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Reviewer: Vinay Singh <vinay...@microsoft.com>
Gerrit-Reviewer: Virali Purbey <virali...@microsoft.com>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Dileep Maurya <dileep...@microsoft.com>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Gaurav Kumar <gaur...@microsoft.com>
Gerrit-CC: Nate Chapin <jap...@chromium.org>
Gerrit-CC: Ragvesh Sharma <rags...@microsoft.com>
Gerrit-CC: Sejal Anand <sejal...@microsoft.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Comment-Date: Wed, 10 Sep 2025 19:57:01 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Divyansh Mangal <dma...@microsoft.com>
Comment-In-Reply-To: Fredrik Söderquist <f...@opera.com>
Comment-In-Reply-To: Kurt Catti-Schmidt <ksc...@microsoft.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Divyansh Mangal (Gerrit)

unread,
Sep 10, 2025, 3:59:35 PM (9 days ago) Sep 10
to Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Fredrik Söderquist, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Divyansh Mangal added 1 comment

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Line 86, Patchset 18: Data(), response.CurrentRequestUrl(), HasSuccessfulRevalidation());
Fredrik Söderquist . unresolved

I think we could just skip a large part of this function if this is true - i.e there should be no need to update the content in any way.

Divyansh Mangal

I have already skipped some part of `UpdateDocument` already, did you mean there are other parts in `SVGDocumentResource::Finish` that we could skip?

Gerrit-Comment-Date: Wed, 10 Sep 2025 19:59:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Fredrik Söderquist <f...@opera.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

chromeperf@appspot.gserviceaccount.com (Gerrit)

unread,
Sep 10, 2025, 7:27:27 PM (8 days ago) Sep 10
to Divyansh Mangal, Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Divyansh Mangal, Fredrik Söderquist, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Message from chrom...@appspot.gserviceaccount.com

📍 Job mac-m1_mini_2020-perf/motionmark1.3.crossbench complete.

See results at: https://pinpoint-dot-chromeperf.appspot.com/job/166be82a510000

Open in Gerrit

Related details

Attention is currently required from:
  • Divyansh Mangal
Gerrit-Attention: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Comment-Date: Wed, 10 Sep 2025 23:27:17 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Fredrik Söderquist (Gerrit)

unread,
Sep 11, 2025, 8:25:07 AM (8 days ago) Sep 11
to Divyansh Mangal, Chromium Metrics Reviews, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Divyansh Mangal, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Fredrik Söderquist added 12 comments

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Line 86, Patchset 18: Data(), response.CurrentRequestUrl(), HasSuccessfulRevalidation());
Fredrik Söderquist . unresolved

I think we could just skip a large part of this function if this is true - i.e there should be no need to update the content in any way.

Divyansh Mangal

I have already skipped some part of `UpdateDocument` already, did you mean there are other parts in `SVGDocumentResource::Finish` that we could skip?

Fredrik Söderquist

The resource hasn't changed, so there shouldn't be a need to re-run that code - and why should we bother that code with this knowledge at all? Similarly here we don't want to potentially cause more side-effects than needed.

File third_party/blink/renderer/core/page/page.cc
Line 590, Patchset 14: String(BrowsingContextGroupToken().ToString()));
Kurt Catti-Schmidt . unresolved

Does this need to be wrapped in a `String`?

Divyansh Mangal

Yes, because `BrowsingContextGroupToken().ToString()` returns `std::string` and there was no implicit conversion between `String` and `std::string`.

Fredrik Söderquist

Maybe we could add a prefix to this identifier to make it a bit more "discoverable" - something like `"svg-resources:<token-string>"` perhaps?

Divyansh Mangal

I have hardcoded the string currently, but I believe we generally create a corresponding string somewhere else?

Fredrik Söderquist

`SVGResourceDocumentCache` (later `...Tracker`) ought to be only entity that needs to care about hot the id is constructed, so in that sense it might be good to move the generation there. If it generated it internally it might've been even better.

File third_party/blink/renderer/core/svg/svg_resource_document_cache.cc
Line 27, Patchset 23 (Latest):#include "base/uuid.h"
Fredrik Söderquist . unresolved

Not used

File third_party/blink/renderer/core/svg/svg_resource_document_content.cc
Line 303, Patchset 23 (Latest): document.Fetcher()->Context().SetSVGCacheIdentifier(
page->GetSVGResourceDocumentCache().GetCacheIdentifier());
Fredrik Söderquist . unresolved

Unnecessary.

Line 307, Patchset 23 (Latest): WebFeature::kPartitionSVGDocumentResourcesInMemoryCache);
Fredrik Söderquist . unresolved

What is this intended to measure/be used for? The name seems like it could be chosen to not be the same as the REF.

File third_party/blink/renderer/core/svg/svg_use_element.cc
Line 651, Patchset 18: if (RuntimeEnabledFeatures::SVGPageLevelCacheIdentifierEnabled() &&
notified_target_observer_) {
return;
}
Fredrik Söderquist . unresolved

This looks like a bodge. This needs to be explained much better (this isn't even mentioned in the commit message). The naming of this field is also poor.

Divyansh Mangal

@f...@opera.com I agree on the ambiguity of this variable, let me try to explain why it was needed:

Consider your html has two <use> element both referencing the same resource. When first <use> fetches the resource and completion happens it will call [1] and notify itself. Then when the second <use> fetches the resources and completion happens it will notify all observers that are observing this resource. So it notifies, first <use> again and itself. This resulted in the first <use> element being notified twice which was not needed (and the DCHECK() at L:665 gets hit).

This behaviour was observed during the testing of WPT [2]

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/loader/resource/svg_document_resource.cc;drc=845d2024791ea649a25c4074bf25263b1f648ff9;l=106.

[2]
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/svg/struct/reftests/use-external-resource-with-revalidation.tentative.html?q=use-external-resource-with-revalidation.tentative.html

I wanted to use the active status of `pending_event_` to do the check instead but was not sure if that's a good fix given the DCHECK at L:665

Fredrik Söderquist

@f...@opera.com I agree on the ambiguity of this variable, let me try to explain why it was needed:

Consider your html has two <use> element both referencing the same resource. When first <use> fetches the resource and completion happens it will call [1] and notify itself. Then when the second <use> fetches the resources and completion happens it will notify all observers that are observing this resource. So it notifies, first <use> again and itself. This resulted in the first <use> element being notified twice which was not needed (and the DCHECK() at L:665 gets hit).

If that happen, then something in how the notifications are generated is broken. All observers should only be notified when the resource changes state. In the example the second `<use>` would get a notification when adding itself as an observer, but no other observers should be notified at that point.

I would suspect that this indicates something may be broken/different with how revalidations are handled. If a new request of the same resource (URL) caused a revalidation, and then all observing `<use>`s are notified, we can choose to either rebuild the shadow tree or not. This currently does the latter.

`pending_event_` can't be used for this, because it's only about the gap between a resource load completing and the corresponding event being sent, while in the above case the event can have been dispatched a long time ago. Setting and unsetting a tracking bool could be done in `UpdateDocumentContent()` (similar to how `load_event_delayer_` is updated) and then cleared again when the notification arrives. The bool needs a more meaningful name though - like `notification_pending_` or something along those lines, to indicate that we've performed an action that we expect to yield a call to `ResourceNotifyFinished()`. The early-out should then be documented so that we know why it's being performed.

Line 657, Patchset 23 (Latest): DCHECK_EQ(document_content_, document_content);
Fredrik Söderquist . unresolved

This should go first in the function.

File third_party/blink/renderer/platform/loader/fetch/fetch_context.h
Line 270, Patchset 23 (Latest): // Returns the SVG cache identifier for SVG document resources.
String GetSVGCacheIdentifier() const { return svg_cache_identifier_; }
void SetSVGCacheIdentifier(const String& cache_identifier) {
svg_cache_identifier_ = cache_identifier;
}

protected:
const Vector<KURL> empty_unused_preloads_;
String svg_cache_identifier_;
Fredrik Söderquist . unresolved

You should extend the frame-specific `FetchContext` so that it accesses the cache id from the `Page`/`SVGResourceDocumentCache`.

File third_party/blink/renderer/platform/loader/fetch/memory_cache.h
Line 179, Patchset 23 (Latest): void RemoveAllResourcesFromMap(ResourceMap* resources);
Fredrik Söderquist . unresolved

Can be made `static`.

File third_party/blink/renderer/platform/loader/fetch/resource_fetcher.cc
Line 1021, Patchset 23 (Latest): GetCacheIdentifier(factory.GetType(), params.GetResourceRequest().Url(),
Fredrik Söderquist . unresolved

Just use the existing `url` (as before).

Line 2940, Patchset 23 (Latest): // For SVG documents, use the SVG-specific cache identifier when the feature
Fredrik Söderquist . unresolved

SVG resource documents

File third_party/blink/renderer/platform/runtime_enabled_features.json5
Line 4746, Patchset 18: name: "SVGPageLevelCacheIdentifier",
Fredrik Söderquist . unresolved

Isn't more like "SvgDocumentResourcesInMemoryCache"(Partition)?

Divyansh Mangal

I have updated it to `PartitionSvgDocumentResourcesInMemoryCache`

Fredrik Söderquist

I think having a name that starts with `"Svg..."` is preferable, because then SVG-related will naturally group.

Open in Gerrit

Related details

Attention is currently required from:
  • Divyansh Mangal
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Comment-Date: Thu, 11 Sep 2025 12:24:49 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Divyansh Mangal (Gerrit)

unread,
Sep 12, 2025, 7:24:46 AM (7 days ago) Sep 12
to Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Fredrik Söderquist, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Divyansh Mangal added 14 comments

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Line 86, Patchset 18: Data(), response.CurrentRequestUrl(), HasSuccessfulRevalidation());
Fredrik Söderquist . unresolved

I think we could just skip a large part of this function if this is true - i.e there should be no need to update the content in any way.

Divyansh Mangal

I have already skipped some part of `UpdateDocument` already, did you mean there are other parts in `SVGDocumentResource::Finish` that we could skip?

Fredrik Söderquist

The resource hasn't changed, so there shouldn't be a need to re-run that code - and why should we bother that code with this knowledge at all? Similarly here we don't want to potentially cause more side-effects than needed.

Divyansh Mangal

I have removed the argument for `UpdateDocument` and the updated the code.
I feel like when revalidation happens few things should happen like

->`LoadingFinished()` should be called.
-> content_ status should be updated to completed.
-> observers should be notified.

I have created a new function `RevalidationFinished` to depict that and rest of the functionality from `SVGDocumentResource::Finish` is utilized as is.
Let me know what you think of the new solution.

File third_party/blink/renderer/core/page/page.cc
Line 590, Patchset 14: String(BrowsingContextGroupToken().ToString()));
Kurt Catti-Schmidt . resolved

Does this need to be wrapped in a `String`?

Divyansh Mangal

Yes, because `BrowsingContextGroupToken().ToString()` returns `std::string` and there was no implicit conversion between `String` and `std::string`.

Fredrik Söderquist

Maybe we could add a prefix to this identifier to make it a bit more "discoverable" - something like `"svg-resources:<token-string>"` perhaps?

Divyansh Mangal

I have hardcoded the string currently, but I believe we generally create a corresponding string somewhere else?

Fredrik Söderquist

`SVGResourceDocumentCache` (later `...Tracker`) ought to be only entity that needs to care about hot the id is constructed, so in that sense it might be good to move the generation there. If it generated it internally it might've been even better.

Divyansh Mangal

Done

File third_party/blink/renderer/core/svg/svg_resource_document_cache.cc
Line 27, Patchset 23:#include "base/uuid.h"
Fredrik Söderquist . resolved

Not used

Divyansh Mangal

Done

File third_party/blink/renderer/core/svg/svg_resource_document_content.h
Line 87, Patchset 14: // `has_successful_revalidation` indicates whether the resource has been
// successfully revalidated.
Kurt Catti-Schmidt . resolved

This feels circular - can you give a more general description that someone not familiar with the code would understand? Something like "`has_successful_revalidation` implies that the underlying object already exists." Or perhaps rename the variable name to `bool element_already_exists`?

Kurt Catti-Schmidt

`element_already_exists` -> `resource_already_exists`

Divyansh Mangal

I want to emphasis on the part that this is happening only cause of revalidation, so I have kept the variable name as is, but I have updated the comment as you suggested. But let me know if you want to discuss about this further.

Divyansh Mangal

Closing this thread as has_successful_revalidation is no longer needed

File third_party/blink/renderer/core/svg/svg_resource_document_content.cc
Line 303, Patchset 23: document.Fetcher()->Context().SetSVGCacheIdentifier(
page->GetSVGResourceDocumentCache().GetCacheIdentifier());
Fredrik Söderquist . resolved

Unnecessary.

Divyansh Mangal

Done

Line 307, Patchset 23: WebFeature::kPartitionSVGDocumentResourcesInMemoryCache);
Fredrik Söderquist . unresolved

What is this intended to measure/be used for? The name seems like it could be chosen to not be the same as the REF.

Divyansh Mangal

I actually wanted to measure how many users are actually using this SVG caching, i thought this might be a good way to metric to have. I placed this piece of code here because I know this is the entry point when caching will actually begin.
I have updated the name to `kCachingSVGDocumentResources`.
Let me know what you think of this?

File third_party/blink/renderer/core/svg/svg_use_element.cc
Line 651, Patchset 18: if (RuntimeEnabledFeatures::SVGPageLevelCacheIdentifierEnabled() &&
notified_target_observer_) {
return;
}
Fredrik Söderquist . unresolved

This looks like a bodge. This needs to be explained much better (this isn't even mentioned in the commit message). The naming of this field is also poor.

Divyansh Mangal

@f...@opera.com I agree on the ambiguity of this variable, let me try to explain why it was needed:

Consider your html has two <use> element both referencing the same resource. When first <use> fetches the resource and completion happens it will call [1] and notify itself. Then when the second <use> fetches the resources and completion happens it will notify all observers that are observing this resource. So it notifies, first <use> again and itself. This resulted in the first <use> element being notified twice which was not needed (and the DCHECK() at L:665 gets hit).

This behaviour was observed during the testing of WPT [2]

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/loader/resource/svg_document_resource.cc;drc=845d2024791ea649a25c4074bf25263b1f648ff9;l=106.

[2]
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/svg/struct/reftests/use-external-resource-with-revalidation.tentative.html?q=use-external-resource-with-revalidation.tentative.html

I wanted to use the active status of `pending_event_` to do the check instead but was not sure if that's a good fix given the DCHECK at L:665

Fredrik Söderquist

@f...@opera.com I agree on the ambiguity of this variable, let me try to explain why it was needed:

Consider your html has two <use> element both referencing the same resource. When first <use> fetches the resource and completion happens it will call [1] and notify itself. Then when the second <use> fetches the resources and completion happens it will notify all observers that are observing this resource. So it notifies, first <use> again and itself. This resulted in the first <use> element being notified twice which was not needed (and the DCHECK() at L:665 gets hit).

If that happen, then something in how the notifications are generated is broken. All observers should only be notified when the resource changes state. In the example the second `<use>` would get a notification when adding itself as an observer, but no other observers should be notified at that point.

I would suspect that this indicates something may be broken/different with how revalidations are handled. If a new request of the same resource (URL) caused a revalidation, and then all observing `<use>`s are notified, we can choose to either rebuild the shadow tree or not. This currently does the latter.

`pending_event_` can't be used for this, because it's only about the gap between a resource load completing and the corresponding event being sent, while in the above case the event can have been dispatched a long time ago. Setting and unsetting a tracking bool could be done in `UpdateDocumentContent()` (similar to how `load_event_delayer_` is updated) and then cleared again when the notification arrives. The bool needs a more meaningful name though - like `notification_pending_` or something along those lines, to indicate that we've performed an action that we expect to yield a call to `ResourceNotifyFinished()`. The early-out should then be documented so that we know why it's being performed.

Divyansh Mangal

I have implemented the suggestion that you gave, as well as commented the usage of `notification_pending_` wherever necessary. Let me know if I missed something

Line 657, Patchset 23: DCHECK_EQ(document_content_, document_content);
Fredrik Söderquist . resolved

This should go first in the function.

Divyansh Mangal

Done

File third_party/blink/renderer/platform/loader/fetch/fetch_context.h
Line 270, Patchset 23: // Returns the SVG cache identifier for SVG document resources.

String GetSVGCacheIdentifier() const { return svg_cache_identifier_; }
void SetSVGCacheIdentifier(const String& cache_identifier) {
svg_cache_identifier_ = cache_identifier;
}

protected:
const Vector<KURL> empty_unused_preloads_;
String svg_cache_identifier_;
Fredrik Söderquist . resolved

You should extend the frame-specific `FetchContext` so that it accesses the cache id from the `Page`/`SVGResourceDocumentCache`.

Divyansh Mangal

Done

File third_party/blink/renderer/platform/loader/fetch/memory_cache.h
Line 179, Patchset 23: void RemoveAllResourcesFromMap(ResourceMap* resources);
Fredrik Söderquist . unresolved

Can be made `static`.

Divyansh Mangal

I was not able to make it `static` as we utilise member function `RemoveInternal` internally.

File third_party/blink/renderer/platform/loader/fetch/resource_fetcher.cc
Line 985, Patchset 18: const String cache_identifier =
RuntimeEnabledFeatures::SVGPageLevelCacheIdentifierEnabled() &&
!params.GetSVGCacheIdentifier().empty()
? params.GetSVGCacheIdentifier()
: GetCacheIdentifier(
params.GetResourceRequest().Url(),
params.GetResourceRequest().GetSkipServiceWorker());
Fredrik Söderquist . resolved

Rather than putting more "gunk" into `FetchParameters`, I think we could get this identifier via the `FetchContext` (and use `factory.GetType()` to limit those calls).

Also, I think we could put this logic in an overload of `GetCacheIdentifier()`.

Divyansh Mangal

I added the setter and getter in `FetchContext` and removed the corresponding from `FetchParameters`. The overloaded is also introduced in the new PatchSet.

Divyansh Mangal

We are extending `FrameFetchContext` so no setter is needed now.

Line 1021, Patchset 23: GetCacheIdentifier(factory.GetType(), params.GetResourceRequest().Url(),
Fredrik Söderquist . resolved

Just use the existing `url` (as before).

Divyansh Mangal

Done

Line 2940, Patchset 23: // For SVG documents, use the SVG-specific cache identifier when the feature
Fredrik Söderquist . resolved

SVG resource documents

Divyansh Mangal

Done

File third_party/blink/renderer/platform/runtime_enabled_features.json5
Line 4746, Patchset 18: name: "SVGPageLevelCacheIdentifier",
Fredrik Söderquist . unresolved

Isn't more like "SvgDocumentResourcesInMemoryCache"(Partition)?

Divyansh Mangal

I have updated it to `PartitionSvgDocumentResourcesInMemoryCache`

Fredrik Söderquist

I think having a name that starts with `"Svg..."` is preferable, because then SVG-related will naturally group.

Divyansh Mangal

Agreed, Updated the flag to `SvgPartitionSVGDocumentResourcesInMemoryCache`

Open in Gerrit

Related details

Attention is currently required from:
  • Fredrik Söderquist
  • Kurt Catti-Schmidt
  • Sejal Anand
  • Vinay Singh
  • Virali Purbey
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I6521e438713a36e491b841ac7b265b247f4b751f
Gerrit-Change-Number: 6807690
Gerrit-PatchSet: 25
Gerrit-Owner: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
Gerrit-Reviewer: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Reviewer: Vinay Singh <vinay...@microsoft.com>
Gerrit-Reviewer: Virali Purbey <virali...@microsoft.com>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Dileep Maurya <dileep...@microsoft.com>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Gaurav Kumar <gaur...@microsoft.com>
Gerrit-CC: Nate Chapin <jap...@chromium.org>
Gerrit-CC: Ragvesh Sharma <rags...@microsoft.com>
Gerrit-CC: Sejal Anand <sejal...@microsoft.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Comment-Date: Fri, 12 Sep 2025 11:24:23 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

Fredrik Söderquist (Gerrit)

unread,
Sep 12, 2025, 8:03:57 AM (7 days ago) Sep 12
to Divyansh Mangal, Chromium Metrics Reviews, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Divyansh Mangal, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Fredrik Söderquist added 2 comments

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Line 86, Patchset 18: Data(), response.CurrentRequestUrl(), HasSuccessfulRevalidation());
Fredrik Söderquist . unresolved

I think we could just skip a large part of this function if this is true - i.e there should be no need to update the content in any way.

Divyansh Mangal

I have already skipped some part of `UpdateDocument` already, did you mean there are other parts in `SVGDocumentResource::Finish` that we could skip?

Fredrik Söderquist

The resource hasn't changed, so there shouldn't be a need to re-run that code - and why should we bother that code with this knowledge at all? Similarly here we don't want to potentially cause more side-effects than needed.

Divyansh Mangal

I have removed the argument for `UpdateDocument` and the updated the code.
I feel like when revalidation happens few things should happen like

->`LoadingFinished()` should be called.
-> content_ status should be updated to completed.
-> observers should be notified.

I have created a new function `RevalidationFinished` to depict that and rest of the functionality from `SVGDocumentResource::Finish` is utilized as is.
Let me know what you think of the new solution.

Fredrik Söderquist
No, none of state should have changed for a successful revalidation - and again the `*Content` object should not be bothered with this. What you could do is split out the main body of this function so that we don't have to indent that code. I.e make this something like:
```
void SVGDocumentResource::Finish(...) {
bool notify_observers = ...;
if (HasSuccessfulRevalidation()) {
notify_observers = content_->IsLoaded();
} else {
notify_observers = UpdateContent();
}
TextResource::Finish(load_finish_time, task_runner);
if (notify_observers) {
...
}
}
bool SVGDocumentResource:::UpdateContent() {
...
}
```
File third_party/blink/renderer/core/svg/svg_resource_document_content.cc
Line 307, Patchset 23: WebFeature::kPartitionSVGDocumentResourcesInMemoryCache);
Fredrik Söderquist . unresolved

What is this intended to measure/be used for? The name seems like it could be chosen to not be the same as the REF.

Divyansh Mangal

I actually wanted to measure how many users are actually using this SVG caching, i thought this might be a good way to metric to have. I placed this piece of code here because I know this is the entry point when caching will actually begin.
I have updated the name to `kCachingSVGDocumentResources`.
Let me know what you think of this?

Fredrik Söderquist

It's not measuring caching, it's measuring all loads.

Open in Gerrit

Related details

Attention is currently required from:
  • Divyansh Mangal
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Comment-Date: Fri, 12 Sep 2025 12:03:43 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Fredrik Söderquist <f...@opera.com>
Comment-In-Reply-To: Divyansh Mangal <dma...@microsoft.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

Fredrik Söderquist (Gerrit)

unread,
Sep 12, 2025, 8:21:42 AM (7 days ago) Sep 12
to Divyansh Mangal, Chromium Metrics Reviews, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Divyansh Mangal, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Fredrik Söderquist added 11 comments

Commit Message
Line 44, Patchset 25 (Latest):3) Proper Disposal of SVG Resources
Fredrik Söderquist . unresolved

Not really introducing this, because you're literally reusing the existing mechanism (as stated in the text here).

File third_party/blink/renderer/core/loader/frame_fetch_context.cc
Line 1251, Patchset 25 (Latest): if (document_ && document_->GetPage()) {
Fredrik Söderquist . unresolved

We should be able to assume that this is true if detached is false.

Line 1251, Patchset 25 (Latest): if (document_ && document_->GetPage()) {
Fredrik Söderquist . unresolved

Use the common pattern of checking for a detached state. (`GetResourceFetcherProperties().IsDetached()`)

File third_party/blink/renderer/core/svg/svg_resource_document_cache.cc
Line 103, Patchset 25 (Latest): to_remove.push_back(resource);
}
}
tracked_resources_.RemoveAll(to_remove);
Fredrik Söderquist . unresolved

Should probably remove the reference from the `MemoryCache` here as well.

File third_party/blink/renderer/core/svg/svg_resource_document_content.cc
Line 37, Patchset 25 (Latest):#include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
Fredrik Söderquist . unresolved

Not used

Line 151, Patchset 25 (Latest): // If IsLoaded() returns true then the document load completed
// synchronously, so we can check if we have a usable document and notify
// our listeners. If not, then we need to wait for the async load completion
// callback.
Fredrik Söderquist . unresolved

Undo the formatting change

File third_party/blink/renderer/core/svg/svg_use_element.h
Line 131, Patchset 25 (Latest): // `ResourceNotifyFinished()`. Used to avoid redundant shadow tree rebuilds
// when multiple notifications arrive for the same resource state change.
Fredrik Söderquist . unresolved

Used to filter out (redundant) multiple notifications for the same resource.

Line 132, Patchset 25 (Latest): // when multiple notifications arrive for the same resource state change.
Fredrik Söderquist . unresolved

Can drop this bit.

Line 130, Patchset 25 (Latest): // Tracks whether we've performed an action that we expect to yield a call to
Fredrik Söderquist . unresolved

We know what this "action" is, so we can spell it out.

File third_party/blink/renderer/core/svg/svg_use_element.cc
Line 676, Patchset 25 (Latest): notification_pending_ = false;
Fredrik Söderquist . unresolved

This should be cleared at the top (since we can return before this). It could make sense to just have a single flah-guarded block at the top.

File third_party/blink/renderer/platform/loader/fetch/memory_cache.h
Line 179, Patchset 23: void RemoveAllResourcesFromMap(ResourceMap* resources);
Fredrik Söderquist . resolved

Can be made `static`.

Divyansh Mangal

I was not able to make it `static` as we utilise member function `RemoveInternal` internally.

Fredrik Söderquist

Acknowledged

Gerrit-Comment-Date: Fri, 12 Sep 2025 12:21:07 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

chromeperf@appspot.gserviceaccount.com (Gerrit)

unread,
Sep 12, 2025, 8:39:41 AM (7 days ago) Sep 12
to Divyansh Mangal, Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Divyansh Mangal, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Message from chrom...@appspot.gserviceaccount.com

😿 Job mac-m1_mini_2020-perf/motionmark1.3.crossbench failed.

See results at: https://pinpoint-dot-chromeperf.appspot.com/job/1595191a510000

Gerrit-Comment-Date: Fri, 12 Sep 2025 12:39:32 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Divyansh Mangal (Gerrit)

unread,
Sep 14, 2025, 2:31:06 PM (5 days ago) Sep 14
to Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Fredrik Söderquist, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Divyansh Mangal added 12 comments

File third_party/blink/renderer/core/loader/frame_fetch_context.cc
Line 1251, Patchset 25: if (document_ && document_->GetPage()) {
Fredrik Söderquist . resolved

We should be able to assume that this is true if detached is false.

Divyansh Mangal

Done

Line 1251, Patchset 25: if (document_ && document_->GetPage()) {
Fredrik Söderquist . resolved

Use the common pattern of checking for a detached state. (`GetResourceFetcherProperties().IsDetached()`)

Divyansh Mangal

Done

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Divyansh Mangal

@f...@opera.com I have updated the code as you suggested, but here's the thing when the resource gets loaded for the first time the resource's status and resource-content's status starts as `kPending` (see `SVGDocumentResource::NotifyStartLoad()`) and when loading finishes the resource's status and resource-content's status becomes `kCached`, problem is when successful revalidation happens once again resource's status and resource-content's status starts as `kPending` but when it finishes resource's status gets updated to `kCached` during `TextResource::Finish(load_finish_time, task_runner)` but with your suggested code resource-content's status remain as `kPending` and even in subsequent function no-one updates it to `kCached`.

I still think that when revalidation is happening some function has to update the status from `kPending` to `kCached` for the resource-content as well since resource status is getting updated from `kPending` to `kCached`.

For that reason, I have kept the `content->RevalidationFinished()` but let me know if you want to discuss on this further.

File third_party/blink/renderer/core/svg/svg_resource_document_cache.cc
Line 103, Patchset 25: to_remove.push_back(resource);
}
}
tracked_resources_.RemoveAll(to_remove);
Fredrik Söderquist . resolved

Should probably remove the reference from the `MemoryCache` here as well.

Divyansh Mangal

Done

File third_party/blink/renderer/core/svg/svg_resource_document_content.cc
Line 37, Patchset 25:#include "third_party/blink/renderer/platform/loader/fetch/fetch_context.h"
#include "third_party/blink/renderer/platform/loader/fetch/fetch_parameters.h"
#include "third_party/blink/renderer/platform/loader/fetch/resource_fetcher.h"
Fredrik Söderquist . resolved

Not used

Divyansh Mangal

Done

Line 151, Patchset 25: // If IsLoaded() returns true then the document load completed

// synchronously, so we can check if we have a usable document and notify
// our listeners. If not, then we need to wait for the async load completion
// callback.
Fredrik Söderquist . resolved

Undo the formatting change

Divyansh Mangal

Done

Line 307, Patchset 23: WebFeature::kPartitionSVGDocumentResourcesInMemoryCache);
Fredrik Söderquist . unresolved

What is this intended to measure/be used for? The name seems like it could be chosen to not be the same as the REF.

Divyansh Mangal

I actually wanted to measure how many users are actually using this SVG caching, i thought this might be a good way to metric to have. I placed this piece of code here because I know this is the entry point when caching will actually begin.
I have updated the name to `kCachingSVGDocumentResources`.
Let me know what you think of this?

Fredrik Söderquist

It's not measuring caching, it's measuring all loads.

Divyansh Mangal

yes, you are right, I have shifted the position of usecounter code a little to better reflect caching. Let me know if its alright.

File third_party/blink/renderer/core/svg/svg_use_element.h
Line 131, Patchset 25: // `ResourceNotifyFinished()`. Used to avoid redundant shadow tree rebuilds

// when multiple notifications arrive for the same resource state change.
Fredrik Söderquist . resolved

Used to filter out (redundant) multiple notifications for the same resource.

Divyansh Mangal

Done

Line 132, Patchset 25: // when multiple notifications arrive for the same resource state change.
Fredrik Söderquist . resolved

Can drop this bit.

Divyansh Mangal

Done

Line 130, Patchset 25: // Tracks whether we've performed an action that we expect to yield a call to
Fredrik Söderquist . resolved

We know what this "action" is, so we can spell it out.

Divyansh Mangal

Done

File third_party/blink/renderer/core/svg/svg_use_element.cc
Line 651, Patchset 18: if (RuntimeEnabledFeatures::SVGPageLevelCacheIdentifierEnabled() &&
notified_target_observer_) {
return;
}
Fredrik Söderquist . resolved

This looks like a bodge. This needs to be explained much better (this isn't even mentioned in the commit message). The naming of this field is also poor.

Divyansh Mangal

@f...@opera.com I agree on the ambiguity of this variable, let me try to explain why it was needed:

Consider your html has two <use> element both referencing the same resource. When first <use> fetches the resource and completion happens it will call [1] and notify itself. Then when the second <use> fetches the resources and completion happens it will notify all observers that are observing this resource. So it notifies, first <use> again and itself. This resulted in the first <use> element being notified twice which was not needed (and the DCHECK() at L:665 gets hit).

This behaviour was observed during the testing of WPT [2]

[1] https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/core/loader/resource/svg_document_resource.cc;drc=845d2024791ea649a25c4074bf25263b1f648ff9;l=106.

[2]
https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/web_tests/external/wpt/svg/struct/reftests/use-external-resource-with-revalidation.tentative.html?q=use-external-resource-with-revalidation.tentative.html

I wanted to use the active status of `pending_event_` to do the check instead but was not sure if that's a good fix given the DCHECK at L:665

Fredrik Söderquist

@f...@opera.com I agree on the ambiguity of this variable, let me try to explain why it was needed:

Consider your html has two <use> element both referencing the same resource. When first <use> fetches the resource and completion happens it will call [1] and notify itself. Then when the second <use> fetches the resources and completion happens it will notify all observers that are observing this resource. So it notifies, first <use> again and itself. This resulted in the first <use> element being notified twice which was not needed (and the DCHECK() at L:665 gets hit).

If that happen, then something in how the notifications are generated is broken. All observers should only be notified when the resource changes state. In the example the second `<use>` would get a notification when adding itself as an observer, but no other observers should be notified at that point.

I would suspect that this indicates something may be broken/different with how revalidations are handled. If a new request of the same resource (URL) caused a revalidation, and then all observing `<use>`s are notified, we can choose to either rebuild the shadow tree or not. This currently does the latter.

`pending_event_` can't be used for this, because it's only about the gap between a resource load completing and the corresponding event being sent, while in the above case the event can have been dispatched a long time ago. Setting and unsetting a tracking bool could be done in `UpdateDocumentContent()` (similar to how `load_event_delayer_` is updated) and then cleared again when the notification arrives. The bool needs a more meaningful name though - like `notification_pending_` or something along those lines, to indicate that we've performed an action that we expect to yield a call to `ResourceNotifyFinished()`. The early-out should then be documented so that we know why it's being performed.

Divyansh Mangal

I have implemented the suggestion that you gave, as well as commented the usage of `notification_pending_` wherever necessary. Let me know if I missed something

Divyansh Mangal

Closing this discussion as we are moving with the `notification_pending_` solution.

Line 676, Patchset 25: notification_pending_ = false;
Fredrik Söderquist . resolved

This should be cleared at the top (since we can return before this). It could make sense to just have a single flah-guarded block at the top.

Divyansh Mangal

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Fredrik Söderquist
  • Kurt Catti-Schmidt
  • Sejal Anand
  • Vinay Singh
  • Virali Purbey
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I6521e438713a36e491b841ac7b265b247f4b751f
Gerrit-Change-Number: 6807690
Gerrit-PatchSet: 27
Gerrit-Owner: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
Gerrit-Reviewer: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Reviewer: Vinay Singh <vinay...@microsoft.com>
Gerrit-Reviewer: Virali Purbey <virali...@microsoft.com>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Dileep Maurya <dileep...@microsoft.com>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Gaurav Kumar <gaur...@microsoft.com>
Gerrit-CC: Nate Chapin <jap...@chromium.org>
Gerrit-CC: Ragvesh Sharma <rags...@microsoft.com>
Gerrit-CC: Sejal Anand <sejal...@microsoft.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
Gerrit-Comment-Date: Sun, 14 Sep 2025 18:30:28 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

Divyansh Mangal (Gerrit)

unread,
Sep 14, 2025, 2:34:46 PM (5 days ago) Sep 14
to Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Fredrik Söderquist, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Divyansh Mangal voted and added 1 comment

Votes added by Divyansh Mangal

Commit-Queue+1

1 comment

Commit Message
Line 44, Patchset 25:3) Proper Disposal of SVG Resources
Fredrik Söderquist . resolved

Not really introducing this, because you're literally reusing the existing mechanism (as stated in the text here).

Divyansh Mangal

It does sounds like I am introducing this change rather than reusing. I have updated the description and added a short note for the garbage disposal mechanism

Open in Gerrit

Related details

Attention is currently required from:
  • Fredrik Söderquist
  • Kurt Catti-Schmidt
  • Sejal Anand
  • Vinay Singh
  • Virali Purbey
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I6521e438713a36e491b841ac7b265b247f4b751f
Gerrit-Change-Number: 6807690
Gerrit-PatchSet: 28
Gerrit-Owner: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
Gerrit-Reviewer: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Reviewer: Vinay Singh <vinay...@microsoft.com>
Gerrit-Reviewer: Virali Purbey <virali...@microsoft.com>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Dileep Maurya <dileep...@microsoft.com>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Gaurav Kumar <gaur...@microsoft.com>
Gerrit-CC: Nate Chapin <jap...@chromium.org>
Gerrit-CC: Ragvesh Sharma <rags...@microsoft.com>
Gerrit-CC: Sejal Anand <sejal...@microsoft.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
Gerrit-Comment-Date: Sun, 14 Sep 2025 18:34:17 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Fredrik Söderquist <f...@opera.com>
satisfied_requirement
unsatisfied_requirement
open
diffy

anne robles (Gerrit)

unread,
Sep 14, 2025, 3:29:35 PM (5 days ago) Sep 14
to Divyansh Mangal, Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Divyansh Mangal, Fredrik Söderquist, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

anne robles added 1 comment

Patchset-level comments
Open in Gerrit

Related details

Attention is currently required from:
  • Divyansh Mangal
Gerrit-CC: anne robles <annero...@gmail.com>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
Gerrit-Attention: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Comment-Date: Sun, 14 Sep 2025 19:28:59 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Fredrik Söderquist (Gerrit)

unread,
Sep 15, 2025, 7:55:54 AM (4 days ago) Sep 15
to Divyansh Mangal, anne robles, Chromium Metrics Reviews, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Divyansh Mangal, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Fredrik Söderquist added 7 comments

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Fredrik Söderquist

Sounds like it could call `UpdateStatus()`. There could be a function to determine the status and then a call to `UpdateStatus()`.

File third_party/blink/renderer/core/svg/svg_resource_document_cache.h
Line 52, Patchset 28 (Latest): static String MakeCacheIdentifier(String browser_context_group_token);
Fredrik Söderquist . unresolved

`StringView`

File third_party/blink/renderer/core/svg/svg_resource_document_cache.cc
Line 35, Patchset 28 (Latest):inline constexpr char kSVGDocumentResourcePrefix[] = "svg-resources:";
Fredrik Söderquist . unresolved

There's no reason for this to live in this namespace. It's only used once, so it can be local to that scope.

File third_party/blink/renderer/core/svg/svg_resource_document_content.cc
Line 307, Patchset 23: WebFeature::kPartitionSVGDocumentResourcesInMemoryCache);
Fredrik Söderquist . unresolved

What is this intended to measure/be used for? The name seems like it could be chosen to not be the same as the REF.

Divyansh Mangal

I actually wanted to measure how many users are actually using this SVG caching, i thought this might be a good way to metric to have. I placed this piece of code here because I know this is the entry point when caching will actually begin.
I have updated the name to `kCachingSVGDocumentResources`.
Let me know what you think of this?

Fredrik Söderquist

It's not measuring caching, it's measuring all loads.

Divyansh Mangal

yes, you are right, I have shifted the position of usecounter code a little to better reflect caching. Let me know if its alright.

Fredrik Söderquist

I still the "caching" bit is uninteresting - there's always caching. Maybe tracking if external SVG document resources are used is interesting to someone, in which case I'd let that ("external") replace caching in the name.

File third_party/blink/renderer/core/svg/svg_use_element.h
Line 130, Patchset 25: // Tracks whether we've performed an action that we expect to yield a call to
Fredrik Söderquist . unresolved

We know what this "action" is, so we can spell it out.

Divyansh Mangal

Done

Fredrik Söderquist

The new version is not correct.

File third_party/blink/renderer/core/svg/svg_use_element.cc
Line 650, Patchset 28 (Latest): // Early-out if we've already been notified for this resource state change.
Fredrik Söderquist . unresolved

Drop

Line 652, Patchset 28 (Latest): // elements to be notified, but we only want to rebuild the shadow tree once
// per actual resource change.
Fredrik Söderquist . unresolved

...when this element has initiated the resource fetch.

Open in Gerrit

Related details

Attention is currently required from:
  • Divyansh Mangal
Gerrit-Attention: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Comment-Date: Mon, 15 Sep 2025 11:55:39 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Divyansh Mangal (Gerrit)

unread,
Sep 15, 2025, 11:35:28 AM (4 days ago) Sep 15
to anne robles, Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Fredrik Söderquist, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Divyansh Mangal added 7 comments

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Divyansh Mangal

@f...@opera.com I tried moving the code around to have a good-looking solution, I have kept the `content->RevalidationFinished()` and based on its return status calling `UpdateStatus` in `UpdateContentStatus`.

One small thing though instead of just using `content_->IsLoaded()` to notify the observer, once I have updated the `content_`'s status then I am notifying the observers. (basically, based on the updated content's status observers should be notified)

Let me know what you think of the new approach.

File third_party/blink/renderer/core/svg/svg_resource_document_cache.h
Line 52, Patchset 28: static String MakeCacheIdentifier(String browser_context_group_token);
Fredrik Söderquist . unresolved

`StringView`

Divyansh Mangal

Updated the change, just curious though is `StringView` optimised for string operations like copying and appending?

File third_party/blink/renderer/core/svg/svg_resource_document_cache.cc
Line 35, Patchset 28:inline constexpr char kSVGDocumentResourcePrefix[] = "svg-resources:";
Fredrik Söderquist . resolved

There's no reason for this to live in this namespace. It's only used once, so it can be local to that scope.

Divyansh Mangal

Moved to local scope

File third_party/blink/renderer/core/svg/svg_resource_document_content.cc
Line 307, Patchset 23: WebFeature::kPartitionSVGDocumentResourcesInMemoryCache);
Fredrik Söderquist . unresolved

What is this intended to measure/be used for? The name seems like it could be chosen to not be the same as the REF.

Divyansh Mangal

I actually wanted to measure how many users are actually using this SVG caching, i thought this might be a good way to metric to have. I placed this piece of code here because I know this is the entry point when caching will actually begin.
I have updated the name to `kCachingSVGDocumentResources`.
Let me know what you think of this?

Fredrik Söderquist

It's not measuring caching, it's measuring all loads.

Divyansh Mangal

yes, you are right, I have shifted the position of usecounter code a little to better reflect caching. Let me know if its alright.

Fredrik Söderquist

I still the "caching" bit is uninteresting - there's always caching. Maybe tracking if external SVG document resources are used is interesting to someone, in which case I'd let that ("external") replace caching in the name.

Divyansh Mangal

Fair enough, updated the variable name to `kExternalSVGDocumentResources`

File third_party/blink/renderer/core/svg/svg_use_element.h
Line 130, Patchset 25: // Tracks whether we've performed an action that we expect to yield a call to
Fredrik Söderquist . unresolved

We know what this "action" is, so we can spell it out.

Divyansh Mangal

Done

Fredrik Söderquist

The new version is not correct.

Divyansh Mangal

My bad, I focused more on the revalidation aspect rather than the action being performed, I have updated it let me know if it need some refining.

File third_party/blink/renderer/core/svg/svg_use_element.cc
Line 650, Patchset 28: // Early-out if we've already been notified for this resource state change.
Fredrik Söderquist . resolved

Drop

Divyansh Mangal

Done

Line 652, Patchset 28: // elements to be notified, but we only want to rebuild the shadow tree once

// per actual resource change.
Fredrik Söderquist . resolved

...when this element has initiated the resource fetch.

Divyansh Mangal

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Fredrik Söderquist
  • Kurt Catti-Schmidt
  • Sejal Anand
  • Vinay Singh
  • Virali Purbey
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I6521e438713a36e491b841ac7b265b247f4b751f
Gerrit-Change-Number: 6807690
Gerrit-PatchSet: 29
Gerrit-Owner: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
Gerrit-Reviewer: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Reviewer: Vinay Singh <vinay...@microsoft.com>
Gerrit-Reviewer: Virali Purbey <virali...@microsoft.com>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Dileep Maurya <dileep...@microsoft.com>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Gaurav Kumar <gaur...@microsoft.com>
Gerrit-CC: Nate Chapin <jap...@chromium.org>
Gerrit-CC: Ragvesh Sharma <rags...@microsoft.com>
Gerrit-CC: Sejal Anand <sejal...@microsoft.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-CC: anne robles <annero...@gmail.com>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
Gerrit-Comment-Date: Mon, 15 Sep 2025 15:34:51 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

Fredrik Söderquist (Gerrit)

unread,
Sep 15, 2025, 12:39:17 PM (4 days ago) Sep 15
to Divyansh Mangal, anne robles, Chromium Metrics Reviews, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Divyansh Mangal, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Fredrik Söderquist added 4 comments

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Fredrik Söderquist

`LoadingFinished()` shouldn't be called in that code-path. If you want to determine the state of the content, then add a function to do that (which needn't have any side-effects) and name it appropriately. With the current factoring `SVGDocumentResource::UpdateContent` and `UpdateContentStatus` are unnecessary (and doesn't really aid readability).

File third_party/blink/renderer/core/svg/svg_resource_document_cache.h
Line 52, Patchset 28: static String MakeCacheIdentifier(String browser_context_group_token);
Fredrik Söderquist . unresolved

`StringView`

Divyansh Mangal

Updated the change, just curious though is `StringView` optimised for string operations like copying and appending?

Fredrik Söderquist

It's optimized for not having to create `String` objects when they are not needed (like in this case).

File third_party/blink/renderer/core/svg/svg_use_element.h
Line 130, Patchset 25: // Tracks whether we've performed an action that we expect to yield a call to
Fredrik Söderquist . resolved

We know what this "action" is, so we can spell it out.

Divyansh Mangal

Done

Fredrik Söderquist

The new version is not correct.

Divyansh Mangal

My bad, I focused more on the revalidation aspect rather than the action being performed, I have updated it let me know if it need some refining.

Fredrik Söderquist

It looks ok now.

File third_party/blink/renderer/platform/runtime_enabled_features.json5
Line 4746, Patchset 18: name: "SVGPageLevelCacheIdentifier",
Fredrik Söderquist . resolved

Isn't more like "SvgDocumentResourcesInMemoryCache"(Partition)?

Divyansh Mangal

I have updated it to `PartitionSvgDocumentResourcesInMemoryCache`

Fredrik Söderquist

I think having a name that starts with `"Svg..."` is preferable, because then SVG-related will naturally group.

Divyansh Mangal

Agreed, Updated the flag to `SvgPartitionSVGDocumentResourcesInMemoryCache`

Fredrik Söderquist

Acknowledged

Open in Gerrit

Related details

Attention is currently required from:
  • Divyansh Mangal
Gerrit-Attention: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Comment-Date: Mon, 15 Sep 2025 16:39:03 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
unsatisfied_requirement
open
diffy

Divyansh Mangal (Gerrit)

unread,
Sep 15, 2025, 4:09:00 PM (4 days ago) Sep 15
to anne robles, Chromium Metrics Reviews, Fredrik Söderquist, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Fredrik Söderquist, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Divyansh Mangal added 2 comments

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Divyansh Mangal

Ohh, in that case I don't think I need to introduce any new functions then a call like `content_->UpdateStatus(GetStatus());` should be sufficient right?
But let me know if I missed something

File third_party/blink/renderer/core/svg/svg_resource_document_cache.h
Line 52, Patchset 28: static String MakeCacheIdentifier(String browser_context_group_token);
Fredrik Söderquist . resolved

`StringView`

Divyansh Mangal

Updated the change, just curious though is `StringView` optimised for string operations like copying and appending?

Fredrik Söderquist

It's optimized for not having to create `String` objects when they are not needed (like in this case).

Divyansh Mangal

Thanks for letting me know!

Open in Gerrit

Related details

Attention is currently required from:
  • Fredrik Söderquist
  • Kurt Catti-Schmidt
  • Sejal Anand
  • Vinay Singh
  • Virali Purbey
Submit Requirements:
  • requirement satisfiedCode-Coverage
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement is not satisfiedNo-Unresolved-Comments
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: chromium/src
Gerrit-Branch: main
Gerrit-Change-Id: I6521e438713a36e491b841ac7b265b247f4b751f
Gerrit-Change-Number: 6807690
Gerrit-PatchSet: 31
Gerrit-Owner: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Divyansh Mangal <dma...@microsoft.com>
Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
Gerrit-Reviewer: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Reviewer: Vinay Singh <vinay...@microsoft.com>
Gerrit-Reviewer: Virali Purbey <virali...@microsoft.com>
Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
Gerrit-CC: Dileep Maurya <dileep...@microsoft.com>
Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
Gerrit-CC: Gaurav Kumar <gaur...@microsoft.com>
Gerrit-CC: Nate Chapin <jap...@chromium.org>
Gerrit-CC: Ragvesh Sharma <rags...@microsoft.com>
Gerrit-CC: Sejal Anand <sejal...@microsoft.com>
Gerrit-CC: Stephen Chenney <sche...@chromium.org>
Gerrit-CC: anne robles <annero...@gmail.com>
Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
Gerrit-Attention: Fredrik Söderquist <f...@opera.com>
Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
Gerrit-Comment-Date: Mon, 15 Sep 2025 20:08:23 +0000
satisfied_requirement
unsatisfied_requirement
open
diffy

Fredrik Söderquist (Gerrit)

unread,
Sep 16, 2025, 9:22:11 AM (3 days ago) Sep 16
to Divyansh Mangal, anne robles, Chromium Metrics Reviews, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
Attention needed from Divyansh Mangal, Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

Fredrik Söderquist voted and added 2 comments

Votes added by Fredrik Söderquist

Code-Review+1

2 comments

File third_party/blink/renderer/core/loader/resource/svg_document_resource.cc
Line 86, Patchset 18: Data(), response.CurrentRequestUrl(), HasSuccessfulRevalidation());
Fredrik Söderquist . resolved
Fredrik Söderquist

Marking resolved

File third_party/blink/renderer/core/svg/svg_resource_document_content.cc
Line 307, Patchset 23: WebFeature::kPartitionSVGDocumentResourcesInMemoryCache);
Fredrik Söderquist . resolved

What is this intended to measure/be used for? The name seems like it could be chosen to not be the same as the REF.

Divyansh Mangal

I actually wanted to measure how many users are actually using this SVG caching, i thought this might be a good way to metric to have. I placed this piece of code here because I know this is the entry point when caching will actually begin.
I have updated the name to `kCachingSVGDocumentResources`.
Let me know what you think of this?

Fredrik Söderquist

It's not measuring caching, it's measuring all loads.

Divyansh Mangal

yes, you are right, I have shifted the position of usecounter code a little to better reflect caching. Let me know if its alright.

Fredrik Söderquist

I still the "caching" bit is uninteresting - there's always caching. Maybe tracking if external SVG document resources are used is interesting to someone, in which case I'd let that ("external") replace caching in the name.

Divyansh Mangal

Fair enough, updated the variable name to `kExternalSVGDocumentResources`

Fredrik Söderquist

Acknowledged

Open in Gerrit

Related details

Attention is currently required from:
  • Divyansh Mangal
  • Kurt Catti-Schmidt
  • Sejal Anand
  • Vinay Singh
  • Virali Purbey
    Submit Requirements:
    • requirement satisfiedCode-Coverage
    • requirement satisfiedCode-Owners
    • requirement satisfiedCode-Review
    Gerrit-Attention: Divyansh Mangal <dma...@microsoft.com>
    Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
    Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
    Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
    Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
    Gerrit-Comment-Date: Tue, 16 Sep 2025 13:21:56 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: Yes
    satisfied_requirement
    open
    diffy

    Divyansh Mangal (Gerrit)

    unread,
    Sep 16, 2025, 9:25:12 AM (3 days ago) Sep 16
    to Fredrik Söderquist, anne robles, Chromium Metrics Reviews, Kurt Catti-Schmidt, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
    Attention needed from Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

    Divyansh Mangal added 1 comment

    Patchset-level comments
    File-level comment, Patchset 31 (Latest):
    Divyansh Mangal . unresolved

    ..

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Kurt Catti-Schmidt
    • Sejal Anand
    • Vinay Singh
    • Virali Purbey
    Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
      Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
      Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
      Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
      Gerrit-Comment-Date: Tue, 16 Sep 2025 13:24:48 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Kurt Catti-Schmidt (Gerrit)

      unread,
      Sep 16, 2025, 4:41:08 PM (3 days ago) Sep 16
      to Divyansh Mangal, Fredrik Söderquist, anne robles, Chromium Metrics Reviews, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
      Attention needed from Divyansh Mangal, Sejal Anand, Vinay Singh and Virali Purbey

      Kurt Catti-Schmidt voted and added 4 comments

      Votes added by Kurt Catti-Schmidt

      Code-Review+1

      4 comments

      Patchset-level comments
      Kurt Catti-Schmidt . resolved

      Just some small suggestions, overall lgtm.

      File third_party/blink/renderer/core/svg/svg_resource_document_cache.h
      Line 65, Patchset 31 (Latest): bool HasContentForTesting(SVGResourceDocumentContent* content);
      Kurt Catti-Schmidt . unresolved

      This should be `const`

      File third_party/blink/renderer/platform/loader/fetch/memory_cache.h
      Line 143, Patchset 31 (Latest): void EvictResourcesForCacheIdentifier(const String& cache_identifier);
      Kurt Catti-Schmidt . unresolved

      This needs a comment (similar to the one above)

      File third_party/blink/renderer/platform/loader/fetch/memory_cache.cc
      Line 435, Patchset 31 (Latest): if (resource_map_iter == resource_maps_.end()) {
      return;
      }
      Kurt Catti-Schmidt . unresolved

      Is this scenario possible? If yes, please add a comment documenting when this occurs. If not, this should this be a `DCHECK_NE(resource_map_iter, resource_maps_.end())`.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Divyansh Mangal
      Gerrit-Attention: Divyansh Mangal <dma...@microsoft.com>
      Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
      Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
      Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
      Gerrit-Comment-Date: Tue, 16 Sep 2025 20:40:46 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Divyansh Mangal (Gerrit)

      unread,
      Sep 18, 2025, 7:03:34 AM (yesterday) Sep 18
      to Kurt Catti-Schmidt, Fredrik Söderquist, anne robles, Chromium Metrics Reviews, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
      Attention needed from Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

      Divyansh Mangal added 3 comments

      File third_party/blink/renderer/core/svg/svg_resource_document_cache.h
      Line 65, Patchset 31: bool HasContentForTesting(SVGResourceDocumentContent* content);
      Kurt Catti-Schmidt . resolved

      This should be `const`

      Divyansh Mangal

      Done

      File third_party/blink/renderer/platform/loader/fetch/memory_cache.h
      Line 143, Patchset 31: void EvictResourcesForCacheIdentifier(const String& cache_identifier);
      Kurt Catti-Schmidt . resolved

      This needs a comment (similar to the one above)

      Divyansh Mangal

      Done

      File third_party/blink/renderer/platform/loader/fetch/memory_cache.cc
      Line 435, Patchset 31: if (resource_map_iter == resource_maps_.end()) {
      return;
      }
      Kurt Catti-Schmidt . unresolved

      Is this scenario possible? If yes, please add a comment documenting when this occurs. If not, this should this be a `DCHECK_NE(resource_map_iter, resource_maps_.end())`.

      Divyansh Mangal

      Hi Kurt, yes, this scenario is possible. So, consider an svg that got added and got removed after sometime. In that case the inner map corresponding to `cache_identifier` exists but it will be empty. And when the Page is getting destroyed this function is called so If I add the DCHECK that you suggested it will give unnecessary error.

      I have added a short comment mentioning this fact. Let me know if that makes sense.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Kurt Catti-Schmidt
      • Sejal Anand
      • Vinay Singh
      • Virali Purbey
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I6521e438713a36e491b841ac7b265b247f4b751f
      Gerrit-Change-Number: 6807690
      Gerrit-PatchSet: 33
      Gerrit-Owner: Divyansh Mangal <dma...@microsoft.com>
      Gerrit-Reviewer: Divyansh Mangal <dma...@microsoft.com>
      Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
      Gerrit-Reviewer: Kurt Catti-Schmidt <ksc...@microsoft.com>
      Gerrit-Reviewer: Vinay Singh <vinay...@microsoft.com>
      Gerrit-Reviewer: Virali Purbey <virali...@microsoft.com>
      Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
      Gerrit-CC: Dileep Maurya <dileep...@microsoft.com>
      Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
      Gerrit-CC: Gaurav Kumar <gaur...@microsoft.com>
      Gerrit-CC: Nate Chapin <jap...@chromium.org>
      Gerrit-CC: Ragvesh Sharma <rags...@microsoft.com>
      Gerrit-CC: Sejal Anand <sejal...@microsoft.com>
      Gerrit-CC: Stephen Chenney <sche...@chromium.org>
      Gerrit-CC: anne robles <annero...@gmail.com>
      Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
      Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
      Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
      Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
      Gerrit-Comment-Date: Thu, 18 Sep 2025 11:03:09 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      Comment-In-Reply-To: Kurt Catti-Schmidt <ksc...@microsoft.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Kurt Catti-Schmidt (Gerrit)

      unread,
      Sep 18, 2025, 5:57:52 PM (13 hours ago) Sep 18
      to Divyansh Mangal, Fredrik Söderquist, anne robles, Chromium Metrics Reviews, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
      Attention needed from Divyansh Mangal, Sejal Anand, Vinay Singh and Virali Purbey

      Kurt Catti-Schmidt voted and added 1 comment

      Votes added by Kurt Catti-Schmidt

      Code-Review+1

      1 comment

      File third_party/blink/renderer/platform/loader/fetch/memory_cache.cc
      Line 435, Patchset 31: if (resource_map_iter == resource_maps_.end()) {
      return;
      }
      Kurt Catti-Schmidt . unresolved

      Is this scenario possible? If yes, please add a comment documenting when this occurs. If not, this should this be a `DCHECK_NE(resource_map_iter, resource_maps_.end())`.

      Divyansh Mangal

      Hi Kurt, yes, this scenario is possible. So, consider an svg that got added and got removed after sometime. In that case the inner map corresponding to `cache_identifier` exists but it will be empty. And when the Page is getting destroyed this function is called so If I add the DCHECK that you suggested it will give unnecessary error.

      I have added a short comment mentioning this fact. Let me know if that makes sense.

      Kurt Catti-Schmidt

      1. "...exists but.." (missing an "s")
      2. This isn't checking that the map is empty, or that the entry is empty. I realize that `find` will return no results when it's empty though. Can you add a DCHECK ensuring that it's empty when this happens?

      ```
      if (resource_map_iter == resource_maps_.end()) {
      DCHECK(resource_maps_.empty());
      return;
      }
      ```

      ...or are there more cases where this can happen? Thinking about it more, this would be cleaner (and maybe more performant) to do an empty check before the `find`, e.g.:

      ```
      // We need to early out in cases where the resource map exist but its empty.
      if(resource_maps_.empty()) {
      return;
      }
      const auto& resource_map_iter = resource_maps_.find(cache_identifier);
      DCHECK_NE(resource_map_iter, resource_maps_.end())
      ```

      My concern is that we don't want to have page identifiers in the cache that aren't supposed to be there, as they could consume extra memory. So having these extra DCHECK's can help avoid bugs.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Divyansh Mangal
      Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
      Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
      Gerrit-Attention: Divyansh Mangal <dma...@microsoft.com>
      Gerrit-Comment-Date: Thu, 18 Sep 2025 21:57:41 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: Yes
      Comment-In-Reply-To: Kurt Catti-Schmidt <ksc...@microsoft.com>
      Comment-In-Reply-To: Divyansh Mangal <dma...@microsoft.com>
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy

      Divyansh Mangal (Gerrit)

      unread,
      6:12 AM (1 hour ago) 6:12 AM
      to Kurt Catti-Schmidt, Fredrik Söderquist, anne robles, Chromium Metrics Reviews, Vinay Singh, Virali Purbey, Dileep Maurya, Ragvesh Sharma, Sejal Anand, Gaurav Kumar, chrom...@appspot.gserviceaccount.com, AyeAye, Chromium LUCI CQ, chromium...@chromium.org, Dirk Schulze, Nate Chapin, Stephen Chenney, asvitkine...@chromium.org, blink-re...@chromium.org, jmedle...@chromium.org, blink-...@chromium.org, fmalit...@chromium.org, gavinp...@chromium.org, kinuko...@chromium.org, kouhe...@chromium.org, loading-re...@chromium.org, loading...@chromium.org, pdr+svgw...@chromium.org
      Attention needed from Kurt Catti-Schmidt, Sejal Anand, Vinay Singh and Virali Purbey

      Divyansh Mangal added 1 comment

      File third_party/blink/renderer/platform/loader/fetch/memory_cache.cc
      Line 435, Patchset 31: if (resource_map_iter == resource_maps_.end()) {
      return;
      }
      Kurt Catti-Schmidt . unresolved

      Is this scenario possible? If yes, please add a comment documenting when this occurs. If not, this should this be a `DCHECK_NE(resource_map_iter, resource_maps_.end())`.

      Divyansh Mangal

      Hi Kurt, yes, this scenario is possible. So, consider an svg that got added and got removed after sometime. In that case the inner map corresponding to `cache_identifier` exists but it will be empty. And when the Page is getting destroyed this function is called so If I add the DCHECK that you suggested it will give unnecessary error.

      I have added a short comment mentioning this fact. Let me know if that makes sense.

      Kurt Catti-Schmidt

      1. "...exists but.." (missing an "s")
      2. This isn't checking that the map is empty, or that the entry is empty. I realize that `find` will return no results when it's empty though. Can you add a DCHECK ensuring that it's empty when this happens?

      ```
      if (resource_map_iter == resource_maps_.end()) {
      DCHECK(resource_maps_.empty());
      return;
      }
      ```

      ...or are there more cases where this can happen? Thinking about it more, this would be cleaner (and maybe more performant) to do an empty check before the `find`, e.g.:

      ```
      // We need to early out in cases where the resource map exist but its empty.
      if(resource_maps_.empty()) {
      return;
      }
      const auto& resource_map_iter = resource_maps_.find(cache_identifier);
      DCHECK_NE(resource_map_iter, resource_maps_.end())
      ```

      My concern is that we don't want to have page identifiers in the cache that aren't supposed to be there, as they could consume extra memory. So having these extra DCHECK's can help avoid bugs.

      Divyansh Mangal

      Hi Kurt, I understand your concern empty case was just one example thats where the DHCECK that you suggested was hitting. Basically, the existence of svg page specific cache identifier does not guarantee there will be a corresponding entry in `ResoureMap` of `MemoryCache`.

      For example, if we try to fetch a svg that was in a data:url, no new resource will be made, since no new resource is being made no new entry in ResourceMap will be added (see working in `ResourceFetcher`) but since we will follow the usual steps of fetching the svg resource, the variable `cache_identifier_` at `SVGResourceDocumentCache` will still be populated. (I have also tested your suggestions and tests like third_party/blink/web_tests/editing/pasteboard/paste-svg-use.html fails due to a similar reason)

      Try to think in this way, whenever we fetch a svg it's not guaranteed to be a success (or it's not guaranteed that we will add in the `MemoryCache`), however we have still created a string at `cache_identifier_` at svg cache level whether there was success or failure. But, there will be no entry corresponding to it at the `MemoryCache` level so we are not consuming any extra memory there. Only string value at `SVGResourceDocumentCache` will persist, which I don't is that much of an issue. Let me know if you want to discuss this further.

      Open in Gerrit

      Related details

      Attention is currently required from:
      • Kurt Catti-Schmidt
      • Sejal Anand
      • Vinay Singh
      • Virali Purbey
      Submit Requirements:
      • requirement satisfiedCode-Coverage
      • requirement satisfiedCode-Owners
      • requirement satisfiedCode-Review
      • requirement is not satisfiedNo-Unresolved-Comments
      Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
      Gerrit-MessageType: comment
      Gerrit-Project: chromium/src
      Gerrit-Branch: main
      Gerrit-Change-Id: I6521e438713a36e491b841ac7b265b247f4b751f
      Gerrit-Change-Number: 6807690
      Gerrit-PatchSet: 34
      Gerrit-Owner: Divyansh Mangal <dma...@microsoft.com>
      Gerrit-Reviewer: Divyansh Mangal <dma...@microsoft.com>
      Gerrit-Reviewer: Fredrik Söderquist <f...@opera.com>
      Gerrit-Reviewer: Kurt Catti-Schmidt <ksc...@microsoft.com>
      Gerrit-Reviewer: Vinay Singh <vinay...@microsoft.com>
      Gerrit-Reviewer: Virali Purbey <virali...@microsoft.com>
      Gerrit-CC: Chromium Metrics Reviews <chromium-met...@google.com>
      Gerrit-CC: Dileep Maurya <dileep...@microsoft.com>
      Gerrit-CC: Dirk Schulze <dsch...@chromium.org>
      Gerrit-CC: Gaurav Kumar <gaur...@microsoft.com>
      Gerrit-CC: Nate Chapin <jap...@chromium.org>
      Gerrit-CC: Ragvesh Sharma <rags...@microsoft.com>
      Gerrit-CC: Sejal Anand <sejal...@microsoft.com>
      Gerrit-CC: Stephen Chenney <sche...@chromium.org>
      Gerrit-CC: anne robles <annero...@gmail.com>
      Gerrit-Attention: Vinay Singh <vinay...@microsoft.com>
      Gerrit-Attention: Kurt Catti-Schmidt <ksc...@microsoft.com>
      Gerrit-Attention: Virali Purbey <virali...@microsoft.com>
      Gerrit-Attention: Sejal Anand <sejal...@microsoft.com>
      Gerrit-Comment-Date: Fri, 19 Sep 2025 10:11:44 +0000
      Gerrit-HasComments: Yes
      Gerrit-Has-Labels: No
      satisfied_requirement
      unsatisfied_requirement
      open
      diffy
      Reply all
      Reply to author
      Forward
      0 new messages