-
Notifications
You must be signed in to change notification settings - Fork 3.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
Introduce code cache and loader V2 #14184
Conversation
⏱️ 23h 2m total CI duration on this PR
|
This stack of pull requests is managed by Graphite. Learn more about stacking. Join @georgemitenkov and the rest of your teammates on Graphite |
ce4af1b
to
a13c2f0
Compare
fc53996
to
75195dc
Compare
6753464
to
5a1517f
Compare
5a1517f
to
f49e8b1
Compare
f49e8b1
to
9647453
Compare
- Helper for struct name index map & type cache for Loader
b6d9e84
to
6f77fe7
Compare
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
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.
No major issues found.
I'd just make sure to:
- Document in a separate document all TODOs introduced by this PR (and there seems to be a lot of them). Then change the comments to refer to that document (or an issue no).
- I'd still do the renaming of some variable and types, like ModuleStorageAdapter, to LegacyModuleStorageAdapter, etc....
Self { | ||
runtime: VMRuntime::new(natives, vm_config), | ||
} | ||
} | ||
|
||
pub fn new_with_runtime_environment(runtime_environment: &RuntimeEnvironment) -> Self { | ||
// Loader V2 does not store any natives, so we save the clone here. |
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.
A bit confusing comment. Seems like runtime_envoronment.natives() should be empty here? Maybe debug_assert?
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 was confusing, fixed. Before, what I did is just avoided clone because V2 loader does not store natives (but they are stored in runtime environment). After addressing comments: removed MoveVM::new
and MoveVM::new_with_config
to ensure VM is always created based on the specified runtime environment (MoveVM::new_with_runtime_environment
). Now there is less duplication, and the code is clear, and less clones in tests.
Ok(module.as_ref().deref().clone()) | ||
}, | ||
Loader::V2(_) => Err(PartialVMError::new( | ||
StatusCode::UNKNOWN_INVARIANT_VIOLATION_ERROR, |
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 should also be unreachable? right? Do we need to handle it gracefully?
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.
Gracefully as if ..? Here we use invariant violation so that we do not panic, in case something goes wrong
module_id.name(), | ||
function_name, | ||
) | ||
// Note: Keeping this consistent with Loader V1 implementation. |
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 like the note, but would add more context, as the V1 code above will be removed.
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.
Added, also changed to TODO, because not remapping the error breaks some tests, but replay might be ok
vm_config, | ||
), | ||
loader, | ||
// Note(loader_v2): We still create this cache, but if V2 loader is used, it is not used. |
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.
nit: even though V2 is not using it. Maybe add a removal plan in the comment?
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.
Done. Changed into a TODO so we can track this
use std::sync::Arc; | ||
|
||
/// Returns the hash (SHA-3-256) of the bytes. Used for both modules and scripts. | ||
pub fn compute_code_hash(bytes: &[u8]) -> [u8; 32] { |
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.
Nit: This can be a generic utility function as well
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.
Changed the name to sha3_256
, and moved to move-vm-types
crate so it serves as a generic utility.
@@ -311,17 +312,12 @@ impl Module { | |||
let module_handle = module.module_handle_at(struct_handle.module); | |||
let module_id = module.module_id_for_handle(module_handle); | |||
|
|||
if module_handle != module.self_handle() { |
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.
That seems right, We might be changing some behavior though by removing these. However, on the other side, if the reply is fine, we should be OK.
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.
LGTM, thanks for amazing improvement.
Current implementation is already very good for us than loader v1 a lot, but if I have to say something, it would be cool if we can use custom type_cache impl in the RuntimeEnvironment
like ModuleStorage
. In our case, we are using code checksum based cache, so want to implement checksum based type_cache impl if possible 👍
In addition to the comments, also force eviction of published modules from global cache. Enable V2 flag for some tests.
@beer-1 good point about the type cache! Let's address this in a separate PR, I added a loader TODO for this to track it. |
@ziaptos thanks for review!
|
- Renamed all types/traits to `Legacy..` - Added TODOs for removal and type cache handling
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
✅ Forge suite
|
✅ Forge suite
|
✅ Forge suite
|
Description
This PR keeps track of all loader & code cache changes, and will be linked to an AIP.
Type of Change
Which Components or Systems Does This Change Impact?
How Has This Been Tested?
Key Areas to Review
Checklist