Status: New
Owner: ----
New issue 2484 by [email protected]: Add Isolate argument to
Number::New()
http://code.google.com/p/v8/issues/detail?id=2484
Right now you can pass an Isolate to Integer::New(), but not to
Number::New(). Is there a specific reason for that?
I have a very light weight function that basically just grabs a value from
memory, recasts and returns it. After trying out some benchmarks between
returning Integer::New() (passing the Isolate) and Number::New(), I noticed
that there was a significant performance difference (60-70%). Which I
realize will be impossible to match because of the Smi optimizations in
place. But figured it could be improved.
So I decided to implement a similar class member to Number and run them
again. Here are the before and after results:
readFloatLE: 414ms 402ms 2.9%
readFloatBE: 521ms 474ms 9.9%
readDoubleLE: 441ms 418ms 5.5%
readDoubleBE: 546ms 479ms 13.9%
So not huge, but it is noticeable in certain cases (and I figured an actual
C++ programmer could probably do better than me ;-)
If you haven't noticed by now, this has been for Node.js. Below are the
code changes I made as an example.
--- a/deps/v8/include/v8.h
+++ b/deps/v8/include/v8.h
@@ -1413,6 +1413,7 @@ class Number : public Primitive {
public:
V8EXPORT double Value() const;
V8EXPORT static Local<Number> New(double value);
+ V8EXPORT static Local<Number> New(double value, Isolate*);
V8_INLINE(static Number* Cast(v8::Value* obj));
private:
V8EXPORT Number();
diff --git a/deps/v8/src/api.cc b/deps/v8/src/api.cc
index 95e5340..45df17e 100644
--- a/deps/v8/src/api.cc
+++ b/deps/v8/src/api.cc
@@ -5272,14 +5272,20 @@ Local<String> v8::String::NewSymbol(const char*
data, int length) {
Local<Number> v8::Number::New(double value) {
- i::Isolate* isolate = i::Isolate::Current();
- EnsureInitializedForIsolate(isolate, "v8::Number::New()");
+ i::Isolate* isolate = i::Isolate::UncheckedCurrent();
+ EnsureInitializedForIsolate(isolate, "v8::Integer::New()");
+ return v8::Number::New(value, reinterpret_cast<Isolate*>(isolate));
+}
+
+Local<Number> v8::Number::New(double value, Isolate* isolate) {
+ i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ ASSERT(internal_isolate->IsInitialized());
if (isnan(value)) {
// Introduce only canonical NaN value into the VM, to avoid signaling
NaNs.
value = i::OS::nan_value();
}
- ENTER_V8(isolate);
- i::Handle<i::Object> result = isolate->factory()->NewNumber(value);
+ ENTER_V8(internal_isolate);
+ i::Handle<i::Object> result =
internal_isolate->factory()->NewNumber(value);
return Utils::NumberToLocal(result);
}
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev