-
Notifications
You must be signed in to change notification settings - Fork 172
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
Implement CairoPie::read_zip_file
#1729
Conversation
|
Benchmark Results for unmodified programs 🚀
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1729 +/- ##
==========================================
+ Coverage 94.78% 94.89% +0.10%
==========================================
Files 100 100
Lines 38322 38425 +103
==========================================
+ Hits 36325 36464 +139
+ Misses 1997 1961 -36 ☔ View full report in Codecov by Sentry. |
vm/src/vm/runners/cairo_pie.rs
Outdated
#[cfg(feature = "std")] | ||
pub fn read_zip_file(file_path: &Path) -> Result<CairoPie, std::io::Error> { | ||
use std::io::Read; | ||
use zip::ZipArchive; | ||
|
||
let file = File::open(file_path)?; | ||
let mut zip_reader = ZipArchive::new(file)?; | ||
|
||
let mut version = vec![]; | ||
zip_reader | ||
.by_name("version.json")? | ||
.read_to_end(&mut version)?; | ||
let version: CairoPieVersion = serde_json::from_slice(&version)?; | ||
|
||
let mut metadata = vec![]; | ||
zip_reader | ||
.by_name("metadata.json")? | ||
.read_to_end(&mut metadata)?; | ||
let metadata: CairoPieMetadata = serde_json::from_slice(&metadata)?; | ||
|
||
let mut memory = vec![]; | ||
zip_reader.by_name("memory.bin")?.read_to_end(&mut memory)?; | ||
let memory = CairoPieMemory::from_bytes(&memory) | ||
.ok_or_else(|| std::io::Error::from(std::io::ErrorKind::InvalidData))?; | ||
|
||
let mut execution_resources = vec![]; | ||
zip_reader | ||
.by_name("execution_resources.json")? | ||
.read_to_end(&mut execution_resources)?; | ||
let execution_resources: ExecutionResources = serde_json::from_slice(&execution_resources)?; | ||
|
||
let mut additional_data = vec![]; | ||
zip_reader | ||
.by_name("additional_data.json")? | ||
.read_to_end(&mut additional_data)?; | ||
let additional_data: CairoPieAdditionalData = serde_json::from_slice(&additional_data)?; | ||
|
||
Ok(CairoPie { | ||
metadata, | ||
memory, | ||
execution_resources, | ||
additional_data, | ||
version, | ||
}) | ||
} |
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 could have a big memory peak from all the read_to_end
calls. Consider deserializing from the readers directly, maybe with a BufReader
.
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.
Alternatively, use and clear a single buffer so at least we don't have all the data in temporaries at the same time.
There seems to be a significant performance regression. |
Co-authored-by: Mario Rugiero <mario.rugiero@lambdaclass.com>
This is quite strange, the benchmarks don't produce or consume Cairo PIEs so they shouldn't be affected by this PR |
Whatever it was it seems to have been reversed by new commits. Maybe it was throttling in the worker. |
let mut memory = vec![]; | ||
zip_reader.by_name("memory.bin")?.read_to_end(&mut memory)?; | ||
let memory = CairoPieMemory::from_bytes(&memory) | ||
.ok_or_else(|| std::io::Error::from(std::io::ErrorKind::InvalidData))?; |
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.
let mut memory = vec![]; | |
zip_reader.by_name("memory.bin")?.read_to_end(&mut memory)?; | |
let memory = CairoPieMemory::from_bytes(&memory) | |
.ok_or_else(|| std::io::Error::from(std::io::ErrorKind::InvalidData))?; | |
let reader = std::io::BufReader::new(zip_reader.by_name("memory.bin")?); | |
let memory = CairoPieMemory::from_reader(reader) | |
.ok_or_else(|| std::io::Error::from(std::io::ErrorKind::InvalidData))?; |
Implements custom deserialization for structs using custom serialization.
Implement method to deserialize a CairoPie from a zip file
Move custom serialization functions into sub-modules along with their added deserialization counterparts to make use of the
serde(with)
attribute and make code cleaner