Skip to content

Commit c8175fc

Browse files
bnoordhuisrvagg
authored andcommitted
src: internalize per-isolate string properties
Speeds up property lookups a little and it creates the string in the old space straight away. It's a little easier on the garbage collector because it doesn't have to track eternalized strings in the new space. PR-URL: #3060 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Trevor Norris <[email protected]>
1 parent ac2bce0 commit c8175fc

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/env-inl.h

+15-1
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,26 @@ inline void Environment::IsolateData::Put() {
3636
}
3737
}
3838

39+
// Create string properties as internalized one byte strings.
40+
//
41+
// Internalized because it makes property lookups a little faster and because
42+
// the string is created in the old space straight away. It's going to end up
43+
// in the old space sooner or later anyway but now it doesn't go through
44+
// v8::Eternal's new space handling first.
45+
//
46+
// One byte because our strings are ASCII and we can safely skip V8's UTF-8
47+
// decoding step. It's a one-time cost, but why pay it when you don't have to?
3948
inline Environment::IsolateData::IsolateData(v8::Isolate* isolate,
4049
uv_loop_t* loop)
4150
: event_loop_(loop),
4251
isolate_(isolate),
4352
#define V(PropertyName, StringValue) \
44-
PropertyName ## _(isolate, FIXED_ONE_BYTE_STRING(isolate, StringValue)),
53+
PropertyName ## _(isolate, \
54+
v8::String::NewFromOneByte( \
55+
isolate, \
56+
reinterpret_cast<const uint8_t*>(StringValue), \
57+
v8::NewStringType::kInternalized, \
58+
sizeof(StringValue) - 1).ToLocalChecked()),
4559
PER_ISOLATE_STRING_PROPERTIES(V)
4660
#undef V
4761
ref_count_(0) {}

src/env.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ namespace node {
3939
#endif
4040

4141
// Strings are per-isolate primitives but Environment proxies them
42-
// for the sake of convenience.
42+
// for the sake of convenience. Strings should be ASCII-only.
4343
#define PER_ISOLATE_STRING_PROPERTIES(V) \
4444
V(address_string, "address") \
4545
V(args_string, "args") \

0 commit comments

Comments
 (0)