From 74f92f21daf8e6d9a9196d2f8fe03c8eadfadaab Mon Sep 17 00:00:00 2001 From: "rafaelw@chromium.org" Date: Wed, 28 May 2014 19:13:41 +0000 Subject: [PATCH] Simplify, speed-up correct-context ObjectObserve calls The original patch which ensured that Object.observe did allocations in the correct context regressed performance about 12%. This patch gets back most of that (about 11%) by simply returning the correct function which is then directly callable from JS, rather than by making the call from the runtime function. A side-effect is that their implementation is shorter. LOG=Y BUG=NONE R=verwaest@chromium.org Review URL: https://codereview.chromium.org/307543008 git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21575 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/object-observe.js | 10 +++-- src/runtime.cc | 47 ++++------------------ src/runtime.h | 6 +-- ...js => getobjectcontextnotifierperformchange.js} | 4 +- ...ext.js => getobjectcontextobjectgetnotifier.js} | 4 +- ...context.js => getobjectcontextobjectobserve.js} | 2 +- 6 files changed, 20 insertions(+), 53 deletions(-) rename test/mjsunit/runtime-gen/{objectnotifierperformchangeinobjectcontext.js => getobjectcontextnotifierperformchange.js} (59%) rename test/mjsunit/runtime-gen/{objectobserveinobjectcontext.js => getobjectcontextobjectgetnotifier.js} (62%) rename test/mjsunit/runtime-gen/{objectgetnotifierinobjectcontext.js => getobjectcontextobjectobserve.js} (82%) diff --git a/src/object-observe.js b/src/object-observe.js index 03afd3f..2dfc752 100644 --- a/src/object-observe.js +++ b/src/object-observe.js @@ -368,7 +368,8 @@ function ObjectObserve(object, callback, acceptList) { if (ObjectIsFrozen(callback)) throw MakeTypeError("observe_callback_frozen"); - return %ObjectObserveInObjectContext(object, callback, acceptList); + var objectObserveFn = %GetObjectContextObjectObserve(object); + return objectObserveFn(object, callback, acceptList); } function NativeObjectObserve(object, callback, acceptList) { @@ -543,8 +544,8 @@ function ObjectNotifierPerformChange(changeType, changeFn) { if (!IS_SPEC_FUNCTION(changeFn)) throw MakeTypeError("observe_perform_non_function"); - return %ObjectNotifierPerformChangeInObjectContext( - objectInfo, changeType, changeFn); + var performChangeFn = %GetObjectContextNotifierPerformChange(objectInfo); + performChangeFn(objectInfo, changeType, changeFn); } function NativeObjectNotifierPerformChange(objectInfo, changeType, changeFn) { @@ -571,7 +572,8 @@ function ObjectGetNotifier(object) { if (!%ObjectWasCreatedInCurrentOrigin(object)) return null; - return %ObjectGetNotifierInObjectContext(object); + var getNotifierFn = %GetObjectContextObjectGetNotifier(object); + return getNotifierFn(object); } function NativeObjectGetNotifier(object) { diff --git a/src/runtime.cc b/src/runtime.cc index c5b60e9..7c3d544 100644 --- a/src/runtime.cc +++ b/src/runtime.cc @@ -14889,64 +14889,33 @@ RUNTIME_FUNCTION(Runtime_ObjectWasCreatedInCurrentOrigin) { } -RUNTIME_FUNCTION(Runtime_ObjectObserveInObjectContext) { +RUNTIME_FUNCTION(Runtime_GetObjectContextObjectObserve) { HandleScope scope(isolate); - ASSERT(args.length() == 3); + ASSERT(args.length() == 1); CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); - CONVERT_ARG_HANDLE_CHECKED(JSFunction, callback, 1); - CONVERT_ARG_HANDLE_CHECKED(Object, accept, 2); Handle context(object->GetCreationContext(), isolate); - Handle function(context->native_object_observe(), isolate); - Handle call_args[] = { object, callback, accept }; - Handle result; - - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, result, - Execution::Call(isolate, function, - handle(context->object_function(), isolate), - ARRAY_SIZE(call_args), call_args, true)); - return *result; + return context->native_object_observe(); } -RUNTIME_FUNCTION(Runtime_ObjectGetNotifierInObjectContext) { +RUNTIME_FUNCTION(Runtime_GetObjectContextObjectGetNotifier) { HandleScope scope(isolate); ASSERT(args.length() == 1); CONVERT_ARG_HANDLE_CHECKED(JSObject, object, 0); Handle context(object->GetCreationContext(), isolate); - Handle function(context->native_object_get_notifier(), isolate); - Handle call_args[] = { object }; - Handle result; - - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, result, - Execution::Call(isolate, function, - handle(context->object_function(), isolate), - ARRAY_SIZE(call_args), call_args, true)); - return *result; + return context->native_object_get_notifier(); } -RUNTIME_FUNCTION(Runtime_ObjectNotifierPerformChangeInObjectContext) { +RUNTIME_FUNCTION(Runtime_GetObjectContextNotifierPerformChange) { HandleScope scope(isolate); - ASSERT(args.length() == 3); + ASSERT(args.length() == 1); CONVERT_ARG_HANDLE_CHECKED(JSObject, object_info, 0); - CONVERT_ARG_HANDLE_CHECKED(String, change_type, 1); - CONVERT_ARG_HANDLE_CHECKED(JSFunction, change_fn, 2); Handle context(object_info->GetCreationContext(), isolate); - Handle function(context->native_object_notifier_perform_change(), - isolate); - Handle call_args[] = { object_info, change_type, change_fn }; - Handle result; - - ASSIGN_RETURN_FAILURE_ON_EXCEPTION( - isolate, result, - Execution::Call(isolate, function, isolate->factory()->undefined_value(), - ARRAY_SIZE(call_args), call_args, true)); - return *result; + return context->native_object_notifier_perform_change(); } diff --git a/src/runtime.h b/src/runtime.h index 566a5eb..1e32d80 100644 --- a/src/runtime.h +++ b/src/runtime.h @@ -306,9 +306,9 @@ namespace internal { F(ObservationWeakMapCreate, 0, 1) \ F(ObserverObjectAndRecordHaveSameOrigin, 3, 1) \ F(ObjectWasCreatedInCurrentOrigin, 1, 1) \ - F(ObjectObserveInObjectContext, 3, 1) \ - F(ObjectGetNotifierInObjectContext, 1, 1) \ - F(ObjectNotifierPerformChangeInObjectContext, 3, 1) \ + F(GetObjectContextObjectObserve, 1, 1) \ + F(GetObjectContextObjectGetNotifier, 1, 1) \ + F(GetObjectContextNotifierPerformChange, 1, 1) \ \ /* Harmony typed arrays */ \ F(ArrayBufferInitialize, 2, 1)\ diff --git a/test/mjsunit/runtime-gen/objectnotifierperformchangeinobjectcontext.js b/test/mjsunit/runtime-gen/getobjectcontextnotifierperformchange.js similarity index 59% rename from test/mjsunit/runtime-gen/objectnotifierperformchangeinobjectcontext.js rename to test/mjsunit/runtime-gen/getobjectcontextnotifierperformchange.js index b5abd32..4c5cdc6 100644 --- a/test/mjsunit/runtime-gen/objectnotifierperformchangeinobjectcontext.js +++ b/test/mjsunit/runtime-gen/getobjectcontextnotifierperformchange.js @@ -2,6 +2,4 @@ // AUTO-GENERATED BY tools/generate-runtime-tests.py, DO NOT MODIFY // Flags: --allow-natives-syntax --harmony var _object_info = new Object(); -var _change_type = "foo"; -var _change_fn = function() {}; -%ObjectNotifierPerformChangeInObjectContext(_object_info, _change_type, _change_fn); +%GetObjectContextNotifierPerformChange(_object_info); diff --git a/test/mjsunit/runtime-gen/objectobserveinobjectcontext.js b/test/mjsunit/runtime-gen/getobjectcontextobjectgetnotifier.js similarity index 62% rename from test/mjsunit/runtime-gen/objectobserveinobjectcontext.js rename to test/mjsunit/runtime-gen/getobjectcontextobjectgetnotifier.js index 55993c8..eb458a2 100644 --- a/test/mjsunit/runtime-gen/objectobserveinobjectcontext.js +++ b/test/mjsunit/runtime-gen/getobjectcontextobjectgetnotifier.js @@ -2,6 +2,4 @@ // AUTO-GENERATED BY tools/generate-runtime-tests.py, DO NOT MODIFY // Flags: --allow-natives-syntax --harmony var _object = new Object(); -var _callback = function() {}; -var _accept = new Object(); -%ObjectObserveInObjectContext(_object, _callback, _accept); +%GetObjectContextObjectGetNotifier(_object); diff --git a/test/mjsunit/runtime-gen/objectgetnotifierinobjectcontext.js b/test/mjsunit/runtime-gen/getobjectcontextobjectobserve.js similarity index 82% rename from test/mjsunit/runtime-gen/objectgetnotifierinobjectcontext.js rename to test/mjsunit/runtime-gen/getobjectcontextobjectobserve.js index 9902c53..3b10b56 100644 --- a/test/mjsunit/runtime-gen/objectgetnotifierinobjectcontext.js +++ b/test/mjsunit/runtime-gen/getobjectcontextobjectobserve.js @@ -2,4 +2,4 @@ // AUTO-GENERATED BY tools/generate-runtime-tests.py, DO NOT MODIFY // Flags: --allow-natives-syntax --harmony var _object = new Object(); -%ObjectGetNotifierInObjectContext(_object); +%GetObjectContextObjectObserve(_object); -- 2.7.4