-
Notifications
You must be signed in to change notification settings - Fork 16
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
perf: single cache file #54
Conversation
rs_lib/src/global/cache_file.rs
Outdated
content: &[u8], | ||
metadata: &SerializedCachedUrlMetadata, | ||
) -> std::io::Result<()> { | ||
let serialized_metadata = serde_json::to_vec(&metadata).unwrap(); |
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.
You can use serde_json::to_writer
, directly into the result
buffer here. Saves one allocation.
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'll try to do an estimate of the capacity.
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.
Oh, we're serializing this for the time lol. I'll change this to a single number.
{
"secs_since_epoch": 1720706015,
"nanos_since_epoch": 697076300
}
fn read_content_and_metadata<TMetadata: DeserializeOwned>( | ||
file_bytes: &[u8], | ||
) -> Option<(&[u8], TMetadata)> { | ||
let (file_bytes, metadata_bytes) = split_content_metadata(file_bytes)?; |
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.
Print a debug!()
if we fail to parse the metadata, or fail to parse the json?
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 think it's ok because we have tests here and in the CLI that ensure the cache is working. Maybe if it becomes an issue?
.time_now() | ||
.duration_since(UNIX_EPOCH) | ||
.unwrap() | ||
.as_secs(), |
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 think only storing seconds is 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
This is for Deno 2. See denoland/deno#17707 for details.
Format:
File format considerations: