<html>
    <head>
      <base href="https://bugs.webkit.org/" />
    </head>
    <body>
      <p>
        <div>
            <b><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Avoid evicting link preload resources when parsing is done."
   href="https://bugs.webkit.org/show_bug.cgi?id=167415#c21">Comment # 21</a>
              on <a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Avoid evicting link preload resources when parsing is done."
   href="https://bugs.webkit.org/show_bug.cgi?id=167415">bug 167415</a>
              from <span class="vcard"><a class="email" href="mailto:yoav&#64;yoav.ws" title="Yoav Weiss &lt;yoav&#64;yoav.ws&gt;"> <span class="fn">Yoav Weiss</span></a>
</span></b>
        <pre>(In reply to <a href="show_bug.cgi?id=167415#c20">comment #20</a>)
<span class="quote">&gt; Comment on <span class=""><a href="attachment.cgi?id=299837&amp;action=diff" name="attach_299837" title="Patch">attachment 299837</a> <a href="attachment.cgi?id=299837&amp;action=edit" title="Patch">[details]</a></span>
&gt; Patch
&gt; 
&gt; I guess an alternative would be to restrict m_preloads to speculative
&gt; preloads only.
&gt; Can we do that?</span >

We probably could, but that would probably mean duplicating the existing mechanisms that relate to m_preloads, or generalize them so that they can be applied to two separate lists. Do you think such a separation would be valuable enough to justify that?

<span class="quote">&gt; Also, if we do not fully clean m_preloads at onload time, won't we keep
&gt; references to these resources?</span >

We fully clear m_preloads when CachedResourceLoader is terminated, so (IIUC) when the document is detached.

<span class="quote">&gt; If so, we might not be able to reclaim memory on these, even if MemoryCache
&gt; is asked to do so.</span >

That's deliberate, as these resources might be used after onload (e.g. by scripts injecting corresponding DOM nodes that need them)

I'm planning to introduce a warning mechanism for unused preloads (probably at 3 seconds after onload). If we want to reclaim memory for these resources before the document detaches, that might be a good point to introduce clearing mechanism for them.

<span class="quote">&gt; 
&gt; View in context:
&gt; <a href="https://bugs.webkit.org/attachment.cgi?id=299837&amp;action=review">https://bugs.webkit.org/attachment.cgi?id=299837&amp;action=review</a>
&gt; 
&gt; &gt; Source/WebCore/ChangeLog:14
&gt; &gt; +        being cleared), said issue is also fixed by clearing previousely preloaded resources if an invalid link preload is later detected.
&gt; 
&gt; What happens if a speculative preload is scheduled first and a link preload
&gt; on the same resource happens after.
&gt; Shouldn't the speculative preload be marked as link preload?</span >

I should probably add handling for that scenario for correctness sake, even if I'm not particularly worried about it.

I think such a scenario would be relatively rare, and even if it happens, clearPreloads(ClearSpeculativePreloads) won't evict this resource from MemoryCache, as it would be referenced by the time clearPreloads is first called.

<span class="quote">&gt; 
&gt; &gt; Source/WebCore/loader/cache/CachedResourceLoader.cpp:870
&gt; &gt; +        resource-&gt;setLinkPreload();
&gt; 
&gt; This should be done in CachedResource constructor.</span >

OK

<span class="quote">&gt; Maybe we should in the future make CachedResource have a
&gt; CachedResourceRequest member.</span ></pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>