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 <gerry@linux.alibaba.com>
  • Loading branch information
jiangliu committed Apr 17, 2023
1 parent 0dc95f8 commit cb79cdb
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion rafs/src/builder/core/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,10 @@ impl Node {

/// Get filename of the inode.
pub fn name(&self) -> &OsStr {
if self.path() == &self.info.source {
let targets = self.target_vec();
if let Some(name) = targets.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 cb79cdb

Please sign in to comment.