-
Notifications
You must be signed in to change notification settings - Fork 122
feat(ethexe/processor): instrument code lazily inside processing #5396
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
base: master
Are you sure you want to change the base?
Changes from 3 commits
a0090db
d10976c
5207bb5
c49cabc
ef6a8c0
5b0107e
acc5408
f104dbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,7 +118,7 @@ use ethexe_common::{ | |
| BlockHeader, CALL_REPLY_SOFT_LIMIT, OUTGOING_MESSAGES_BYTES_SOFT_LIMIT, | ||
| OUTGOING_MESSAGES_SOFT_LIMIT, PROGRAM_MODIFICATIONS_SOFT_LIMIT, PromisePolicy, | ||
| StateHashWithQueueSize, | ||
| db::CodesStorageRO, | ||
| db::{CodesStorageRO, CodesStorageRW}, | ||
| gear::{CHUNK_PROCESSING_GAS_LIMIT, MessageType}, | ||
| injected::Promise, | ||
| }; | ||
|
|
@@ -341,7 +341,7 @@ pub(super) trait RunContext { | |
| pub(crate) struct CommonRunContext { | ||
| pub(super) db: Database, | ||
| pub(super) transitions: InBlockTransitions, | ||
| instance_creator: InstanceCreator, | ||
| pub(super) instance_creator: InstanceCreator, | ||
| gas_allowance_counter: GasAllowanceCounter, | ||
| outgoing_messages_limiter: u32, | ||
| outgoing_messages_bytes_limiter: u32, | ||
|
|
@@ -409,7 +409,7 @@ impl RunContext for CommonRunContext { | |
| .ok_or_else(|| ProcessorError::MissingCodeIdForProgram(program_id)) | ||
| })?; | ||
|
|
||
| instrumented_code_and_metadata(&self.db, code_id) | ||
| instrumented_code_and_metadata(&self.db, &self.instance_creator, code_id) | ||
| } | ||
|
|
||
| fn states(&self, processing_queue_type: MessageType) -> Vec<ActorStateHashWithQueueSize> { | ||
|
|
@@ -427,14 +427,32 @@ impl RunContext for CommonRunContext { | |
|
|
||
| pub(super) fn instrumented_code_and_metadata( | ||
| db: &Database, | ||
| instance_creator: &InstanceCreator, | ||
| code_id: CodeId, | ||
| ) -> Result<(InstrumentedCode, CodeMetadata)> { | ||
| db.instrumented_code(ethexe_runtime_common::VERSION, code_id) | ||
| .and_then(|instrumented_code| { | ||
| db.code_metadata(code_id) | ||
| .map(|metadata| (instrumented_code, metadata)) | ||
| }) | ||
| .ok_or_else(|| ProcessorError::MissingInstrumentedCodeForProgram(code_id)) | ||
| if let Some(instrumented_code) = db.instrumented_code(ethexe_runtime_common::VERSION, code_id) | ||
| && let Some(metadata) = db.code_metadata(code_id) | ||
| { | ||
| return Ok((instrumented_code, metadata)); | ||
| } | ||
|
|
||
| let original_code = db | ||
| .original_code(code_id) | ||
| .ok_or(ProcessorError::MissingOriginalCodeForProgram(code_id))?; | ||
|
|
||
| let mut instance = instance_creator.instantiate()?; | ||
| let (instrumented_code, code_metadata) = instance | ||
| .instrument(&original_code)? | ||
| .ok_or(ProcessorError::MissingInstrumentedCodeForProgram(code_id))?; | ||
|
|
||
| db.set_instrumented_code( | ||
| ethexe_runtime_common::VERSION, | ||
| code_id, | ||
| instrumented_code.clone(), | ||
| ); | ||
| db.set_code_metadata(code_id, code_metadata.clone()); | ||
|
Comment on lines
+468
to
+473
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When References
|
||
|
|
||
| Ok((instrumented_code, code_metadata)) | ||
| } | ||
|
|
||
| pub(super) fn states( | ||
|
|
||
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.
Instantiating a new Wasmtime instance for every uninstrumented code blob can be expensive. Given that code instrumentation is a heavy operation, this adds significant overhead. In
spawn_chunk_execution, if a chunk contains multiple programs with uninstrumented code, this will happen multiple times. AlthoughInstanceCreator::instantiateis optimized viaInstancePre, you might consider instantiating the runtime once per chunk processing pass and reusing it for all required instrumentations within that pass to reduce overhead.References