haikuwebkit/JSTests/microbenchmarks/weak-set-constructor.js

14 lines
186 B
JavaScript
Raw Permalink Normal View History

Optimize constructors of ES6 collections https://bugs.webkit.org/show_bug.cgi?id=223953 Reviewed by Yusuke Suzuki. JSTests: * microbenchmarks/map-constructor.js: * microbenchmarks/set-constructor.js: Added. * microbenchmarks/weak-map-constructor.js: Added. * microbenchmarks/weak-set-constructor.js: Added. * stress/map-constructor-adder.js: * stress/set-constructor-adder.js: * stress/weak-map-constructor-adder-error-cross-realm.js: Added. * stress/weak-map-constructor-adder.js: * stress/weak-set-constructor-adder-error-cross-realm.js: Added. * stress/weak-set-constructor-adder.js: * stress/weak-set-constructor.js: Source/JavaScriptCore: This patch speeds up the constructors by avoiding call() for non-observable "set" / "add" methods and using getIndex() for Map / WeakMap collections. For Map / Set, this change leverages existing cloning helpers, which rely on watchpoints, to avoid even a method lookup. However, slower path is used for subclasses. Results in 1.9x speed-up for common case. For WeakMap / WeakSet, adder function is checked by C++ pointer, which enables fast path even for cross-realm subclasses. Results in 2.3x progression. Both approaches require special handling of a cross-realm NewTarget to ensure that raised exceptions (OOM / TypeError) belong to realm of the adder function, and not to constructor's or NewTarget's. Also, adds descriptve error messages for non-callable "set" / "add" properties. * runtime/JSMap.cpp: (JSC::JSMap::isSetFastAndNonObservable): (JSC::JSMap::canCloneFastAndNonObservable): Deleted. * runtime/JSMap.h: * runtime/JSSet.cpp: (JSC::JSSet::isAddFastAndNonObservable): (JSC::JSSet::canCloneFastAndNonObservable): Deleted. * runtime/JSSet.h: * runtime/MapConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * runtime/SetConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * runtime/WeakMapConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * runtime/WeakMapPrototype.cpp: (JSC::WeakMapPrototype::finishCreation): (JSC::JSC_DEFINE_HOST_FUNCTION): * runtime/WeakMapPrototype.h: * runtime/WeakSetConstructor.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * runtime/WeakSetPrototype.cpp: (JSC::WeakSetPrototype::finishCreation): (JSC::JSC_DEFINE_HOST_FUNCTION): * runtime/WeakSetPrototype.h: LayoutTests: * js/dom/basic-weakset-expected.txt: git-svn-id: https://svn.webkit.org/repository/webkit/trunk@275271 268f45cc-cd09-0410-ab3c-d52691b4dbfc Canonical link: https://commits.webkit.org/235956@main
2021-03-31 07:21:37 +00:00
function test(array)
{
return new WeakSet(array);
}
noInline(test);
var array = [];
for (var j = 0; j < 50; ++j)
array[j] = {};
for (var i = 0; i < 1e4; ++i)
test(array);