Skip to content
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

refactor(*): add source.as_bytes() #454

Merged
merged 1 commit into from
Jan 22, 2024
Merged

Conversation

Mossaka
Copy link
Member

@Mossaka Mossaka commented Jan 18, 2024

This PR is a preferred way to refactor the usage of Source into a as_bytes() function in Context. It does not change the APIs of the Engine trait. Closes #448

@Mossaka Mossaka changed the title refactor(*): add source.into_cow() refactor(*): add source.into_bytes() Jan 18, 2024
@Mossaka Mossaka closed this Jan 18, 2024
@Mossaka Mossaka reopened this Jan 18, 2024
@Mossaka Mossaka changed the title refactor(*): add source.into_bytes() refactor(*): add source.as_bytes() Jan 18, 2024
Signed-off-by: jiaxiao zhou <jiazho@microsoft.com>
Copy link
Contributor

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

.resolve_in_path_or_cwd()
.next()
.context("module not found")?;
Ok(Cow::Owned(std::fs::read(path)?))
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thought: We optimize for no copy in the Oci case by using Cow, but we read the file every time in the File case. Might be premature optimiation, but the file content could be cached in memory here to avoid multiple reads.
I'm fine with leaving it as it is because the unoptimized File case would be the legacy workflow. Also we could revisit if we ever observe any perforance bottleneck here.

Copy link
Collaborator

@jprendes jprendes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@Mossaka Mossaka merged commit 6bee9dd into containerd:main Jan 22, 2024
43 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants