From: yurys@chromium.org Date: Fri, 2 Mar 2012 12:27:15 +0000 (+0000) Subject: Cache result of ScriptNameOrSourceURL function. The function is quite slow on large... X-Git-Tag: upstream/4.7.83~17215 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=827e827b385ce17dd5634724511a4768b2d801e6;p=platform%2Fupstream%2Fv8.git Cache result of ScriptNameOrSourceURL function. The function is quite slow on large(several MBs) scripts which causes significant slowdown when capturing stack trace for such scripts. Review URL: https://chromiumcodereview.appspot.com/9564012 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10902 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- diff --git a/src/messages.js b/src/messages.js index e641133dd..cc72e8f09 100644 --- a/src/messages.js +++ b/src/messages.js @@ -533,6 +533,13 @@ function ScriptNameOrSourceURL() { if (this.name) { return this.name; } + + // The result is cached as on long scripts it takes noticable time to search + // for the sourceURL. + if (this.hasCachedNameOrSourceURL) + return this.cachedNameOrSourceURL; + this.hasCachedNameOrSourceURL = true; + // TODO(608): the spaces in a regexp below had to be escaped as \040 // because this file is being processed by js2c whose handling of spaces // in regexps is broken. Also, ['"] are excluded from allowed URLs to @@ -541,6 +548,7 @@ function ScriptNameOrSourceURL() { // the scanner/parser. var source = ToString(this.source); var sourceUrlPos = %StringIndexOf(source, "sourceURL=", 0); + this.cachedNameOrSourceURL = this.name; if (sourceUrlPos > 4) { var sourceUrlPattern = /\/\/@[\040\t]sourceURL=[\040\t]*([^\s\'\"]*)[\040\t]*$/gm; @@ -551,15 +559,17 @@ function ScriptNameOrSourceURL() { var match = %_RegExpExec(sourceUrlPattern, source, sourceUrlPos - 4, matchInfo); if (match) { - return SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]); + this.cachedNameOrSourceURL = + SubString(source, matchInfo[CAPTURE(2)], matchInfo[CAPTURE(3)]); } } - return this.name; + return this.cachedNameOrSourceURL; } SetUpLockedPrototype(Script, - $Array("source", "name", "line_ends", "line_offset", "column_offset"), + $Array("source", "name", "line_ends", "line_offset", "column_offset", + "cachedNameOrSourceURL", "hasCachedNameOrSourceURL" ), $Array( "lineFromPosition", ScriptLineFromPosition, "locationFromPosition", ScriptLocationFromPosition,