[WebAssembly] Optimize JS to Wasm call by using pointer of Signature as SignatureIndex
authoryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Sep 2018 17:29:04 +0000 (17:29 +0000)
committeryusukesuzuki@slowstart.org <yusukesuzuki@slowstart.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 7 Sep 2018 17:29:04 +0000 (17:29 +0000)
commitce53feb8aa7ddc5e89adbf6e8bf838e969111fab
treeed8bc2dd7a7da1230f09eb16a8f64e35d9796d4d
parent4b10f0055f30138a4bd80821d785cf9b10745d79
[WebAssembly] Optimize JS to Wasm call by using pointer of Signature as SignatureIndex
https://bugs.webkit.org/show_bug.cgi?id=189401

Reviewed by Mark Lam.

SignatureInformation is a global repository for Signature to make Signature atomic.
It takes Ref<Signature>&& and generates SignatureIndex. And we get const Signature&
by using this SignatureIndex. However, converting SignatureIndex to const Signature&
always looks up a hash table. This is costly since JS to Wasm calls always use
Signature& to check types of arguments.

Instead of using this hash table, this patch uses a pointer of Signature as SignatureIndex.
This allows us to convert SignatureIndex to Signature by just casting it.

We also optimize SignatureInformation::singleton by making an accessor function inlined.
And we move ProtoCallFrame::init to the header since it's just setting values.

This change significantly optimizes JS to wasm calls (1e7 times) from 600ms to 320ms.

In the future, we can remove SignatureIndex by directly handling Ref<Signature>: adding
deref() of Signature which unregisters itself from SignatureInformation carefully. Or we can
make SignatureIndex uint32_t by introducing a mechanism similar to StructureID.

* JavaScriptCore.xcodeproj/project.pbxproj:
* Sources.txt:
* interpreter/ProtoCallFrame.h:
(JSC::ProtoCallFrame::init):
* wasm/WasmB3IRGenerator.cpp:
(JSC::Wasm::B3IRGenerator::addCallIndirect):
* wasm/WasmBBQPlan.cpp:
* wasm/WasmFormat.h:
(JSC::Wasm::WasmToWasmImportableFunction::offsetOfSignatureIndex):
* wasm/WasmFunctionParser.h:
* wasm/WasmModule.h:
* wasm/WasmOMGPlan.cpp:
* wasm/WasmSectionParser.cpp:
(JSC::Wasm::SectionParser::parseType):
* wasm/WasmSignature.cpp:
(JSC::Wasm::SignatureInformation::adopt):
(JSC::Wasm::SignatureInformation::tryCleanup):
(JSC::Wasm::SignatureInformation::singleton): Deleted.
(JSC::Wasm::SignatureInformation::get): Deleted.
* wasm/WasmSignature.h:
(JSC::Wasm::Signature::index const):
(JSC::Wasm::SignatureHash::SignatureHash):
(JSC::Wasm::SignatureHash::hash):
(JSC::Wasm::SignatureHash::isHashTableDeletedValue const):
(JSC::Wasm::SignatureHash::empty): Deleted.
(JSC::Wasm::SignatureHash::deleted): Deleted.
* wasm/WasmSignatureInlines.h: Renamed from Source/JavaScriptCore/interpreter/ProtoCallFrame.cpp.
(JSC::Wasm::SignatureInformation::singleton):
(JSC::Wasm::SignatureInformation::get):
* wasm/js/JSToWasm.cpp:
* wasm/js/JSWebAssemblyModule.h:
* wasm/js/WasmToJS.cpp:
(JSC::Wasm::wasmToJS):
* wasm/js/WebAssemblyFunction.cpp:
* wasm/js/WebAssemblyModuleRecord.cpp:
* wasm/js/WebAssemblyWrapperFunction.cpp:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@235786 268f45cc-cd09-0410-ab3c-d52691b4dbfc
20 files changed:
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/Sources.txt
Source/JavaScriptCore/interpreter/ProtoCallFrame.h
Source/JavaScriptCore/wasm/WasmB3IRGenerator.cpp
Source/JavaScriptCore/wasm/WasmBBQPlan.cpp
Source/JavaScriptCore/wasm/WasmFormat.h
Source/JavaScriptCore/wasm/WasmFunctionParser.h
Source/JavaScriptCore/wasm/WasmModule.h
Source/JavaScriptCore/wasm/WasmOMGPlan.cpp
Source/JavaScriptCore/wasm/WasmSectionParser.cpp
Source/JavaScriptCore/wasm/WasmSignature.cpp
Source/JavaScriptCore/wasm/WasmSignature.h
Source/JavaScriptCore/wasm/WasmSignatureInlines.h [moved from Source/JavaScriptCore/interpreter/ProtoCallFrame.cpp with 55% similarity]
Source/JavaScriptCore/wasm/js/JSToWasm.cpp
Source/JavaScriptCore/wasm/js/JSWebAssemblyModule.h
Source/JavaScriptCore/wasm/js/WasmToJS.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyFunction.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyModuleRecord.cpp
Source/JavaScriptCore/wasm/js/WebAssemblyWrapperFunction.cpp