Skip to content

Commit

Permalink
rafs: optimize Node::name() to reduce image build time
Browse files Browse the repository at this point in the history
According to perf flamegraph, Node::name() costs too much time
when generating nydus images from tar files. So optimize it.

Signed-off-by: Jiang Liu <[email protected]>
  • Loading branch information
jiangliu committed Apr 18, 2023
1 parent 52d5639 commit 6b78bd1
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion rafs/src/builder/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,9 @@ impl Node {

/// Get filename of the inode.
pub fn name(&self) -> &OsStr {
if self.path() == &self.info.source {
if let Some(name) = self.target_vec().last() {
name
} else if self.path() == &self.info.source {
OsStr::from_bytes(ROOT_PATH_NAME)
} else {
// Safe to unwrap because `path` is returned from `path()` which is canonicalized
Expand Down

0 comments on commit 6b78bd1

Please sign in to comment.