WebKit Bugzilla
New
Browse
Search+
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED DUPLICATE of
bug 81466
79125
CachedScriptSourceProvider::getRange can unnecessarily make a full copy of the source
https://bugs.webkit.org/show_bug.cgi?id=79125
Summary
CachedScriptSourceProvider::getRange can unnecessarily make a full copy of th...
Yong Li
Reported
2012-02-21 10:38:46 PST
JSC::UString getRange(int start, int end) should share the existing StringImpl when it is asked to return the full range. patch is forthcoming
Attachments
the patch
(1.78 KB, patch)
2012-02-21 10:53 PST
,
Yong Li
pnormand
: commit-queue-
Details
Formatted Diff
Diff
Try again
(1.78 KB, patch)
2012-02-21 11:05 PST
,
Yong Li
no flags
Details
Formatted Diff
Diff
another try
(1.72 KB, patch)
2012-02-21 12:53 PST
,
Yong Li
no flags
Details
Formatted Diff
Diff
updated
(1.77 KB, patch)
2012-02-21 13:09 PST
,
Yong Li
no flags
Details
Formatted Diff
Diff
More
(2.85 KB, patch)
2012-02-22 08:27 PST
,
Yong Li
no flags
Details
Formatted Diff
Diff
new patch
(2.33 KB, patch)
2012-05-03 10:06 PDT
,
Yong Li
darin
: review-
buildbot
: commit-queue-
Details
Formatted Diff
Diff
use substring() now
(2.71 KB, patch)
2012-05-04 08:58 PDT
,
Yong Li
no flags
Details
Formatted Diff
Diff
substring()
(2.70 KB, patch)
2012-05-04 09:00 PDT
,
Yong Li
no flags
Details
Formatted Diff
Diff
Show Obsolete
(8)
View All
Add attachment
proposed patch, testcase, etc.
Yong Li
Comment 1
2012-02-21 10:53:50 PST
Created
attachment 127998
[details]
the patch
Philippe Normand
Comment 2
2012-02-21 10:57:44 PST
Comment on
attachment 127998
[details]
the patch
Attachment 127998
[details]
did not pass gtk-ews (gtk): Output:
http://queues.webkit.org/results/11562167
Early Warning System Bot
Comment 3
2012-02-21 11:00:34 PST
Comment on
attachment 127998
[details]
the patch
Attachment 127998
[details]
did not pass qt-ews (qt): Output:
http://queues.webkit.org/results/11562168
Yong Li
Comment 4
2012-02-21 11:05:37 PST
Created
attachment 128001
[details]
Try again
Yong Li
Comment 5
2012-02-21 12:51:53 PST
Comment on
attachment 128001
[details]
Try again Actually I can make it better
Yong Li
Comment 6
2012-02-21 12:53:30 PST
Created
attachment 128026
[details]
another try
Yong Li
Comment 7
2012-02-21 13:09:49 PST
Created
attachment 128031
[details]
updated
Yong Li
Comment 8
2012-02-22 08:27:00 PST
Created
attachment 128219
[details]
More Prevent CachedScript from resetting m_script when its string buffer is still referenced by others because doing so won't save any memory but cause extra memory usage if scritp() is called on the CachedScript afterwards.
Yong Li
Comment 9
2012-02-23 06:54:00 PST
Comment on
attachment 128219
[details]
More The change in CachedScript may be unnecessary and also uncomplete.
Yong Li
Comment 10
2012-02-23 06:54:27 PST
Comment on
attachment 128031
[details]
updated Go back to this simple change
Yong Li
Comment 11
2012-05-03 10:06:06 PDT
Created
attachment 140039
[details]
new patch
Eric Seidel (no email)
Comment 12
2012-05-03 10:10:47 PDT
Comment on
attachment 140039
[details]
new patch Don't we have a String::substring() or StringImpl::substring() call which would do this optimization for us?
Build Bot
Comment 13
2012-05-03 10:33:40 PDT
Comment on
attachment 140039
[details]
new patch
Attachment 140039
[details]
did not pass mac-ews (mac): Output:
http://queues.webkit.org/results/12606210
Yong Li
Comment 14
2012-05-03 10:39:52 PDT
(In reply to
comment #12
)
> (From update of
attachment 140039
[details]
) > Don't we have a String::substring() or StringImpl::substring() call which would do this optimization for us?
Yes we do. My previous patch uses substringSharingImpl(). But I feel it is a little bit confusing because it hints that, no matter where the substring is, it would always share the original buffer. That might or might not be good, because the CachedScript will destroy decoded script. Actually substringSharingImpl() creates new copy if the substring is not the full string. But the name isn't so accurate.
Darin Adler
Comment 15
2012-05-03 15:57:28 PDT
Comment on
attachment 140039
[details]
new patch View in context:
https://bugs.webkit.org/attachment.cgi?id=140039&action=review
> Source/WebCore/bindings/js/CachedScriptSourceProvider.h:59 > ASSERT(start + length <= this->length()); > > String script = m_cachedScript->script(); > + > + if (!start && length == script.length()) > + return stringToUString(script); > + > return JSC::UString(StringImpl::create(script.impl(), start, length));
This whole thing can be done as a one-liner, without all those assertions, using the substring function, which already correctly optimizes the case of a range covering the entire string. return stringToUString(m_cachedScript->script().substring(start, end - start));
> Source/WebCore/bindings/js/StringSourceProvider.h:54 > ASSERT(length >= 0); > ASSERT(start + length <= this->length()); > > + if (!start && length == m_source.length()) > + return stringToUString(m_source); > + > return JSC::UString(StringImpl::create(m_source.impl(), start, length));
Same here: return stringToUString(m_source.substring(start, end - start));
Yong Li
Comment 16
2012-05-04 08:57:30 PDT
(In reply to
comment #15
)
> (From update of
attachment 140039
[details]
) > View in context:
https://bugs.webkit.org/attachment.cgi?id=140039&action=review
> > > Source/WebCore/bindings/js/CachedScriptSourceProvider.h:59 > > ASSERT(start + length <= this->length()); > > > > String script = m_cachedScript->script(); > > + > > + if (!start && length == script.length()) > > + return stringToUString(script); > > + > > return JSC::UString(StringImpl::create(script.impl(), start, length)); > > This whole thing can be done as a one-liner, without all those assertions, using the substring function, which already correctly optimizes the case of a range covering the entire string. > > return stringToUString(m_cachedScript->script().substring(start, end - start)); >
Hm... Didn't realize substring() can do that since some day. substring() also does sanity checks. so no need for those asserts now. patch is forthcoming
Yong Li
Comment 17
2012-05-04 08:58:05 PDT
Created
attachment 140246
[details]
use substring() now
Yong Li
Comment 18
2012-05-04 09:00:43 PDT
Created
attachment 140247
[details]
substring()
Yong Li
Comment 19
2012-05-07 11:49:53 PDT
Comment on
attachment 140247
[details]
substring() Actually the issue has been fixed with the latest code:
http://trac.webkit.org/changeset/111358
Bug 81466
Yong Li
Comment 20
2012-05-07 11:50:24 PDT
*** This bug has been marked as a duplicate of
bug 81466
***
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug