Bug 39460 - Javascript image prefetching does not report to squirrelfish GC
Summary: Javascript image prefetching does not report to squirrelfish GC
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore JavaScript (show other bugs)
Version: 528+ (Nightly build)
Hardware: All All
: P2 Normal
Assignee: Nathan Lawrence
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-05-20 17:27 PDT by Nathan Lawrence
Modified: 2010-05-28 00:58 PDT (History)
7 users (show)

See Also:


Attachments
Suggested patch (2.58 KB, patch)
2010-05-20 17:28 PDT, Nathan Lawrence
no flags Details | Formatted Diff | Diff
Updated 56651 (2.66 KB, patch)
2010-05-20 17:46 PDT, Nathan Lawrence
mrowe: review-
Details | Formatted Diff | Diff
more style changes. (2.68 KB, patch)
2010-05-21 15:04 PDT, Nathan Lawrence
ggaren: review-
Details | Formatted Diff | Diff
Fixed test case. (3.57 KB, patch)
2010-05-27 16:36 PDT, Nathan Lawrence
no flags Details | Formatted Diff | Diff
removed <img> and <image> tag checks. (1.94 KB, patch)
2010-05-27 19:00 PDT, Nathan Lawrence
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Nathan Lawrence 2010-05-20 17:27:01 PDT
When an image is preloaded in javascript, the size of the image is never reported to the javascript garbage collector.  If a large image is repeatedly preloaded but never used, it will not free any of the images until the garbage collector has run out of space to allocate any new free javascript variables.
Comment 1 Nathan Lawrence 2010-05-20 17:28:56 PDT
Created attachment 56651 [details]
Suggested patch

Adds a check to see if an image is loaded but is not part of the document.
Comment 2 WebKit Review Bot 2010-05-20 17:37:16 PDT
Attachment 56651 [details] did not pass style-queue:

Failed to run "['WebKitTools/Scripts/check-webkit-style', '--no-squash']" exit_code: 1
WebCore/manual-tests/image-prefetch-stress.html:6:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:7:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:8:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:9:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:10:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:14:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:15:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:16:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:17:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:18:  Line contains tab character.  [whitespace/tab] [5]
WebCore/manual-tests/image-prefetch-stress.html:19:  Line contains tab character.  [whitespace/tab] [5]
Total errors found: 11 in 2 files


If any of these errors are false positives, please file a bug against check-webkit-style.
Comment 3 WebKit Review Bot 2010-05-20 17:41:10 PDT
Attachment 56651 [details] did not build on chromium:
Build output: http://webkit-commit-queue.appspot.com/results/2301384
Comment 4 Nathan Lawrence 2010-05-20 17:46:28 PDT
Created attachment 56654 [details]
Updated 56651

Updates style changes and adds ifdefs around JSC specific code.
Comment 5 Mark Rowe (bdash) 2010-05-21 00:13:33 PDT
Comment on attachment 56654 [details]
Updated 56651

Your manual test references a file URL that exists only on your machine.  You should either update the test to use an image that exists in the SVN repository or add a suitable image alongside the test.
Comment 6 Geoffrey Garen 2010-05-21 08:48:38 PDT
> JSC::JSGlobalData *globalData

WebKit style puts the "*" next to the type name, since "pointer" is logically a party of the type.

> +i = 0;
> +setInterval(function(){
> +    x = new Image();

Need 'var' in front of these two variable declarations for "i" and "x".

With this patch, how many images load / how much memory is used before GC triggers?
Comment 7 Nathan Lawrence 2010-05-21 15:04:19 PDT
Created attachment 56749 [details]
more style changes.

re ggaren:
It should garbage collect after maxExtraCost additional memory has been reported to the garbage collector (what appears to be a megabyte).  On my system, with only the manual test running in the browser, the usage doesn't seem to get above 130MB.
Comment 8 Geoffrey Garen 2010-05-21 16:30:51 PDT
Comment on attachment 56749 [details]
more style changes.

I asked Nathan to take another look at this because the patch doesn't seem to fully solve the problem. In his test, about 130MB of image data is still reported as allocated, and the number of live JSHTMLImageElements still increases linearly.
Comment 9 Nathan Lawrence 2010-05-27 16:36:28 PDT
Created attachment 57280 [details]
Fixed test case.

It appears that the number of live HTMLImageElements is still increasing because the image elements are being created faster than they can load creating a backlog of images to be loaded.  The new test case doesn't load images as quickly, showing that the patch does in fact work.
Comment 10 Geoffrey Garen 2010-05-27 17:30:19 PDT
Comment on attachment 57280 [details]
Fixed test case.

r=me
Comment 11 WebKit Commit Bot 2010-05-27 17:45:09 PDT
Comment on attachment 57280 [details]
Fixed test case.

Clearing flags on attachment: 57280

Committed r60337: <http://trac.webkit.org/changeset/60337>
Comment 12 WebKit Commit Bot 2010-05-27 17:45:15 PDT
All reviewed patches have been landed.  Closing bug.
Comment 13 Simon Fraser (smfr) 2010-05-27 17:47:52 PDT
Is a similar fix needed for Audio and Video elements?
Comment 14 Geoffrey Garen 2010-05-27 18:06:33 PDT
(In reply to comment #13)
> Is a similar fix needed for Audio and Video elements?

Do those elements preload while outside the document? If so, yes.
Comment 15 Geoffrey Garen 2010-05-27 18:08:49 PDT
Dan pointed out on IRC that checking just for the <img> tag is probably sufficient, since that's what new Image uses.
Comment 16 Simon Fraser (smfr) 2010-05-27 18:24:34 PDT
(In reply to comment #14)
> Do those elements preload while outside the document? If so, yes.

Indeed they do. I filed bug 39858.
Comment 17 Nathan Lawrence 2010-05-27 18:59:57 PDT
Because not just <img> and <image> elements can preload images, we don't want to restrict based on the element associated with the loader.
Comment 18 Nathan Lawrence 2010-05-27 19:00:34 PDT
Created attachment 57287 [details]
removed <img> and <image> tag checks.
Comment 19 Geoffrey Garen 2010-05-27 23:44:04 PDT
Comment on attachment 57287 [details]
removed <img> and <image> tag checks.

r=me
Comment 20 WebKit Commit Bot 2010-05-28 00:58:44 PDT
Comment on attachment 57287 [details]
removed <img> and <image> tag checks.

Clearing flags on attachment: 57287

Committed r60345: <http://trac.webkit.org/changeset/60345>
Comment 21 WebKit Commit Bot 2010-05-28 00:58:50 PDT
All reviewed patches have been landed.  Closing bug.