-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
v8: add cachedDataVersionTag #11515
v8: add cachedDataVersionTag #11515
Conversation
I have two issues with this approach:
|
@bnoordhuis, very legitimate points.
|
Given the very v8 specific nature of this, would it make sense to add an API to the |
@jasnell We could do that but it would be weird having it on a completely different module than where the actual caching occurs. We could probably reserve some specific value ( |
Still seems a bit troublesome. I'd really not expose something new on |
I feel the same way, the thing is that that ship has kind of sailed when we added the cached data stuff in the first place. ;) |
Perhaps we can add a property with a neutral-ish name to the result object? node-chakra could implement that by omitting it or setting it to zero. diff --git a/src/env.h b/src/env.h
index 581d7e9..5e1ee13 100644
--- a/src/env.h
+++ b/src/env.h
@@ -74,9 +74,10 @@ namespace node {
V(bytes_string, "bytes") \
V(bytes_parsed_string, "bytesParsed") \
V(bytes_read_string, "bytesRead") \
- V(cached_data_string, "cachedData") \
V(cached_data_produced_string, "cachedDataProduced") \
V(cached_data_rejected_string, "cachedDataRejected") \
+ V(cached_data_string, "cachedData") \
+ V(cached_data_tag_string, "cachedDataTag") \
V(callback_string, "callback") \
V(change_string, "change") \
V(oncertcb_string, "oncertcb") \
diff --git a/src/node_contextify.cc b/src/node_contextify.cc
index 9b0ab4e..5a08347 100644
--- a/src/node_contextify.cc
+++ b/src/node_contextify.cc
@@ -573,6 +573,10 @@ class ContextifyScript : public BaseObject {
reinterpret_cast<const char*>(cached_data->data),
cached_data->length);
args.This()->Set(env->cached_data_string(), buf.ToLocalChecked());
+ args.This()->Set(
+ env->cached_data_tag_string(),
+ Integer::NewFromUnsigned(env->isolate(),
+ ScriptCompiler::CachedDataVersionTag()));
}
args.This()->Set(
env->cached_data_produced_string(), |
@bnoordhuis the reason I wanted it as a method was to be able to know before doing expensive IO loading a cached value if it's likely to work or not. |
doc/api/vm.md
Outdated
@@ -22,6 +22,14 @@ added: v0.3.1 | |||
Instances of the `vm.Script` class contain precompiled scripts that can be | |||
executed in specific sandboxes (or "contexts"). | |||
|
|||
## vm.Script.cachedDataVersionTag() | |||
<!-- YAML | |||
added: v7.x.x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use added: REPLACEME
doc/api/vm.md
Outdated
--> | ||
|
||
Returns an integer representing the version tag for `cachedData` for the current V8 version & flags. | ||
* This value is meant only for determining whether a previously generated `cachedData` buffer is still valid; the tag has no other meaning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn’t really need to be a list, does it? (Also, we prefer line wrapping at 80 characters)
Can you go into more detail on your use case? I'm trying to understand how and where you'd use the tag. |
@bnoordhuis, sure, in v8-compile-cache I store all of the cached data in a single file. That turns out to be a lot faster, than to load lots of small individual files of cached data as needed. But this means that if the cache data doesn't match your v8+cpu+flags, then you loaded that for nothing. I'm deploying this across a fleet of mostly homogenous machines, which means that I can pre-generate the cached data and ship it with the code. However, if a machine is one of the different ones, I'd like to be able to know that my cache won't work early on instead of waiting for a rejection. If I had const cachePath = path.join(CACHE_PATH, vm.Script.cachedDataVersionTag() + '.MAP');
if (fs.existsSync(cachePath)) {
loadExistingCache(cachePath);
} else {
createNewCache();
} |
Okay, thanks. I think a James suggested passing the script object as an argument but I don't think that's necessary, the return value is independent of the script object. |
Yep, I had misread the original PR. Agree that having it sit off |
Adds `vm.Script.cachedDataVersionTag()`, which returns an integer representing the version tag for `cachedData` for the current V8 version & flags.
hmmm. why aren't the CI tests running? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because it needs to be started manually. :-)
LGTM with a suggestion. CI: https://ci.nodejs.org/job/node-test-pull-request/6680/
doc/api/v8.md
Outdated
|
||
Returns an integer representing a "version tag" derived from the V8 version, | ||
command line flags and detected CPU features. This is useful for determining | ||
whether a [`vm.Script`][] `cachedData` buffer is compatible with another V8. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd s/another V8/this instance of V8/ to emphasize that it applies to the running instance of V8.
Landed in 70beef9, thanks for the PR! 🎉 |
Adds `v8.cachedDataVersionTag()`, which returns an integer representing the version tag for `cachedData` for the current V8 version & flags. PR-URL: #11515 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]>
The test provided in this PR is failing when this change is cherry-picked v7.x-staging.
I wonder if the value being derived from the command line flags is a change that only exists in a more recent version of v8? /cc @nodejs/v8 For now, I'm going to hold off landing in v7.x |
Weird, v7.x-staging's Lines 2300 to 2304 in fdb4a6c
Lines 2356 to 2360 in efaab8f
|
Ah but |
Adds
v8.cachedDataVersionTag()
, which returns an integer representing the version tag forcachedData
for the current V8 version & flags. Closes #11506.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesAffected core subsystem(s)
v8