-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[JSC] Do not declare callee name when it is function declaration
https://bugs.webkit.org/show_bug.cgi?id=264030 rdar://117786144 Reviewed by Alexey Shvayka. We should declare callee only when it is not function declarations. Otherwise, we taint the scope with that, and unnecessarily create a JSLexicalEnvironment when it gets captured. function test(n) { if (n) { (function(n) { test(n - 1); }(n)); } } In the above code, if `test` function is function declaration, we should define `test` name in the upper scope and we do not need to declare it inside the function. We propagate FunctionMode in Parser and use it as the same way to BytecodeGenerator. Microbenchmark shows improvement since we wipe JSLexicalEnvironment allocations. ToT Patched function-declaration-name 32.8020+-0.3279 ^ 27.4767+-0.2500 ^ definitely 1.1938x faster * Source/JavaScriptCore/API/JSScriptRef.cpp: (parseScript): * Source/JavaScriptCore/API/glib/JSCContext.cpp: (jsc_context_check_syntax): * Source/JavaScriptCore/builtins/BuiltinExecutables.cpp: (JSC::BuiltinExecutables::createExecutable): * Source/JavaScriptCore/bytecode/UnlinkedFunctionExecutable.cpp: (JSC::generateUnlinkedFunctionCodeBlock): * Source/JavaScriptCore/debugger/DebuggerParseData.cpp: (JSC::gatherDebuggerParseData): * Source/JavaScriptCore/parser/Parser.cpp: (JSC::Parser<LexerType>::Parser): (JSC::Parser<LexerType>::parseInner): * Source/JavaScriptCore/parser/Parser.h: (JSC::Parser::functionMode const): (JSC::parse): (JSC::parseFunctionForFunctionConstructor): * Source/JavaScriptCore/parser/ParserModes.h: * Source/JavaScriptCore/runtime/CodeCache.cpp: (JSC::generateUnlinkedCodeBlockImpl): * Source/JavaScriptCore/runtime/Completion.cpp: (JSC::checkSyntaxInternal): (JSC::checkModuleSyntax): * Source/JavaScriptCore/runtime/JSModuleLoader.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): Canonical link: https://commits.webkit.org/270095@main
- Loading branch information
1 parent
2b7aa25
commit 3e0dc21
Showing
12 changed files
with
39 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
function shouldBe(actual, expected) { | ||
if (actual !== expected) | ||
throw new Error('bad value: ' + actual); | ||
} | ||
|
||
(function () { | ||
"use strict"; | ||
function test(n, count) { | ||
if (n) { | ||
return (function (n, count) { | ||
return test(n, count); | ||
}(n - 1, count + 1)); | ||
} | ||
return count; | ||
} | ||
shouldBe(test(1e7, 0), 1e7); | ||
}()); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters