<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>208683</bug_id>
          
          <creation_ts>2020-03-05 18:32:54 -0800</creation_ts>
          <short_desc>Delete encoded data from CachedImage once image is created</short_desc>
          <delta_ts>2020-05-11 16:10:57 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>Images</component>
          <version>WebKit Nightly Build</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=207531</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Basuke Suzuki">basuke</reporter>
          <assigned_to name="Basuke Suzuki">basuke</assigned_to>
          <cc>basuke</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1626435</commentid>
    <comment_count>0</comment_count>
    <who name="Basuke Suzuki">basuke</who>
    <bug_when>2020-03-05 18:32:54 -0800</bug_when>
    <thetext>Encoded data won&apos;t be used after image is successfully created. It can be cleared.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1626482</commentid>
    <comment_count>1</comment_count>
      <attachid>392667</attachid>
    <who name="Basuke Suzuki">basuke</who>
    <bug_when>2020-03-05 20:42:05 -0800</bug_when>
    <thetext>Created attachment 392667
PATCH</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1627868</commentid>
    <comment_count>2</comment_count>
    <who name="Basuke Suzuki">basuke</who>
    <bug_when>2020-03-09 11:57:40 -0700</bug_when>
    <thetext>Copied from Slack conversation: https://webkit.slack.com/archives/CU64U6FDW/p1583469841216300

smfr
I’m suspicious of this. doesn’t memory pressure clear the image cache, which means we’ll need to go back and decoded using the encoded data?

yusukesuzuki  4 days ago
Yes. Memory pressure clears the decoded data. So, we can clear the data only if (1) the decoded content can represent the entire value, and (2) the memory pressure handler does not clear it.

Let’s consider about the example,

Unicode source CachedScript data and it is not file-backed.

This case, we are doubling the size basically because unicode string cannot be represented from SharedBuffer without decoding, and SharedBuffer needs to keep the content while it is not file backed.

In this case, this is reasonable that, purging SharedBuffer and holding decoded data, and do not purge decoded data when the low memory handler happens

(1) is it possible that we see many non-file backed data? (edited) 

A1. old Membuster is saying yes. We should measure this on new Membuster. (edited) 

A2. On iOS, yes. Our threshold for file backed data is very high (16KB) in iOS. (edited) 

basuke:beer:
Ah, that make sense. Unfortunately our platform do not handle low memory situation well. That’s why I didn’t hit the case. 

I’ll revisit this soon after taking care of memory pressure.

yusukesuzuki
Right, OK. But at the same time, I believe that we should not rely on low memory handler to reduce memory usage. In the ideal world, we should have control system which attempt to shrink memory well when we are doing idle. And I (personally) believe that JSC GC could take this role (managing all the memory usage). @smfr Do you have some idea? (edited) 

smfr
i’m not sure GC should be this thing. I’d prefer some kind of cache manger that knows about all the caches

yusukesuzuki
Why I would like to put this in GC is that I believe that we should attempt to make memory small even if we are using JSC framework. But it is also good that some manager can make memory shrink if this manager works well in JSC framework too.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1651506</commentid>
    <comment_count>3</comment_count>
    <who name="Basuke Suzuki">basuke</who>
    <bug_when>2020-05-11 16:10:57 -0700</bug_when>
    <thetext>Encoded image shouldn&apos;t be deleted as Simon says.</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>392667</attachid>
            <date>2020-03-05 20:42:05 -0800</date>
            <delta_ts>2020-03-05 20:42:05 -0800</delta_ts>
            <desc>PATCH</desc>
            <filename>bug-208683.diff</filename>
            <type>text/plain</type>
            <size>1273</size>
            <attacher name="Basuke Suzuki">basuke</attacher>
            
              <data encoding="base64">ZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZyBiL1NvdXJjZS9XZWJDb3JlL0No
YW5nZUxvZwppbmRleCBlY2NjOTAxMzQ2ZGQuLmQyZjAyMTEwNzk5MCAxMDA2NDQKLS0tIGEvU291
cmNlL1dlYkNvcmUvQ2hhbmdlTG9nCisrKyBiL1NvdXJjZS9XZWJDb3JlL0NoYW5nZUxvZwpAQCAt
MSwzICsxLDE1IEBACisyMDIwLTAzLTA1ICBCYXN1a2UgU3V6dWtpICA8YmFzdWtlLnN1enVraUBz
b255LmNvbT4KKworICAgICAgICBEZWxldGUgZW5jb2RlZCBkYXRhIGZyb20gQ2FjaGVkSW1hZ2Ug
b25jZSBpbWFnZSBpcyBjcmVhdGVkCisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3No
b3dfYnVnLmNnaT9pZD0yMDg2ODMKKworICAgICAgICBSZXZpZXdlZCBieSBOT0JPRFkgKE9PUFMh
KS4KKworICAgICAgICBObyBiZWhhdmlvciBjaGFuZ2UuCisKKyAgICAgICAgKiBsb2FkZXIvY2Fj
aGUvQ2FjaGVkSW1hZ2UuY3BwOgorICAgICAgICAoV2ViQ29yZTo6Q2FjaGVkSW1hZ2U6OmZpbmlz
aExvYWRpbmcpOgorCiAyMDIwLTAzLTAyICBXZW5zb24gSHNpZWggIDx3ZW5zb25faHNpZWhAYXBw
bGUuY29tPgogCiAgICAgICAgIE1ha2UgUGF0aDo6UGF0aChjb25zdCBQYXRoJikgYW5kIFBhdGg6
Om9wZXJhdG9yPShjb25zdCBQYXRoJikgY2hlYXAKZGlmZiAtLWdpdCBhL1NvdXJjZS9XZWJDb3Jl
L2xvYW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