Skip to content

refactor: use Vec<OsString> path-component keys in coloring map#341

Closed
Copilot wants to merge 22 commits intomasterfrom
copilot/address-pr-339-discussion-point
Closed

refactor: use Vec<OsString> path-component keys in coloring map#341
Copilot wants to merge 22 commits intomasterfrom
copilot/address-pr-339-discussion-point

Conversation

Copy link
Contributor

Copilot AI commented Mar 7, 2026

Coloring's internal map used PathBuf as keys, causing PathBuf::join() to copy all ancestor bytes at every recursion level in build_coloring_map — O(total_path_bytes) work per internal node.

Changes

  • src/visualizer/coloring.rsmap: HashMap<PathBuf, Color>HashMap<Vec<OsString>, Color>; node_color now accepts &[OsString] instead of &Path
  • src/app/sub.rsbuild_coloring_map refactored to use a mutable push/pop stack (&mut Vec<OsString>); cloning happens only at leaf insertions, not at every internal node; PathBuf is still assembled per-leaf for file_color() OS stat calls
  • src/visualizer/methods.rs — lookup path constructed as Vec<OsString> instead of PathBuf::collect()
  • tests/usual_cli.rs — manual map entries updated to Vec<OsString> keys

Before (clone full path at every node):

fn build_coloring_map(node: ..., path: PathBuf, map: &mut HashMap<PathBuf, Color>) {
    let node_path = path.join(node.name().as_os_str()); // copies all ancestor bytes
    for child in node.children() {
        build_coloring_map(child, node_path.clone(), map); // clones again per child
    }
}

After (push/pop stack, clone only at leaves):

fn build_coloring_map(node: ..., path_stack: &mut Vec<OsString>, map: &mut HashMap<Vec<OsString>, Color>) {
    path_stack.push(node.name().as_os_str().to_os_string());
    if node.children().is_empty() {
        map.insert(path_stack.clone(), color); // one clone per leaf
    } else {
        for child in node.children() {
            build_coloring_map(child, path_stack, map); // no clone during traversal
        }
    }
    path_stack.pop();
}

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/KSXGitHub/parallel-disk-usage/pulls/339/comments
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (http block)

If you need me to access, download, or install something from one of these locations, you can either:


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 20 commits March 6, 2026 17:55
Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…ify rendering

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…, update docs

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
… remove redundant attributes

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…structure TreeHorizontalSlice

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…ucturing

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…ice/aligned_plain_slice

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…loredTreeHorizontalSlice

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…re coloring, move color logic to App::run

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…erse-kinds workspace, fix tests

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…_COLORS

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
… lint

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…ollision

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
… ansi_prefixes to ls_colors, update doc comment, make lscolors optional under color feature

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
…endency

Co-authored-by: KSXGitHub <11488886+KSXGitHub@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix issue raised in PR 339 discussion refactor: use Vec<OsString> path-component keys in coloring map Mar 7, 2026
@github-actions
Copy link

github-actions bot commented Mar 7, 2026

Performance Regression Reports

commit: 0a14ab2

--quantity=block-size --max-depth=10 --min-ratio=0.01 --progress --no-sort
Command Mean [ms] Min [ms] Max [ms] Relative
pdu 115.7 ± 31.8 104.4 206.1 1.10 ± 0.30
pdu-0.20.0 104.7 ± 0.3 104.1 105.3 1.00
Logs
Benchmark 1: pdu
  Time (mean ± σ):     115.7 ms ±  31.8 ms    [User: 103.3 ms, System: 289.6 ms]
  Range (min … max):   104.4 ms … 206.1 ms    28 runs
 
  Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system without any interferences from other programs. It might help to use the '--warmup' or '--prepare' options.
 
Benchmark 2: pdu-0.20.0
  Time (mean ± σ):     104.7 ms ±   0.3 ms    [User: 104.8 ms, System: 287.3 ms]
  Range (min … max):   104.1 ms … 105.3 ms    28 runs
 
Summary
  pdu-0.20.0 ran
    1.10 ± 0.30 times faster than pdu
JSON
{
  "results": [
    {
      "command": "pdu",
      "mean": 0.11565717823142858,
      "stddev": 0.03182600536287003,
      "median": 0.10483375516000001,
      "user": 0.10325187999999998,
      "system": 0.28960444714285716,
      "min": 0.10444145916,
      "max": 0.20611908016000002,
      "times": [
        0.10483360616000001,
        0.10536676816,
        0.10498553216,
        0.10463197716,
        0.20560741016000003,
        0.20611908016000002,
        0.10481444016000001,
        0.10444145916,
        0.10494726716000001,
        0.10468409116,
        0.10479486016,
        0.10473025816,
        0.10454814716000001,
        0.10471061216000001,
        0.10484728916000001,
        0.10493740916000001,
        0.10461414016000001,
        0.10457954516000001,
        0.20589323116000002,
        0.10526272016,
        0.10522843616000001,
        0.10483390416,
        0.10483886316,
        0.10494731716000001,
        0.10471859716000001,
        0.10500092816,
        0.10466757116,
        0.10481552916
      ],
      "exit_codes": [
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ]
    },
    {
      "command": "pdu-0.20.0",
      "mean": 0.10467846512428576,
      "stddev": 0.0002601303160709016,
      "median": 0.10471571666000001,
      "user": 0.1048030942857143,
      "system": 0.28734730428571414,
      "min": 0.10414432716000001,
      "max": 0.10528667516000001,
      "times": [
        0.10480003016,
        0.10481312516,
        0.10432635916,
        0.10476139716,
        0.10414432716000001,
        0.10500939416,
        0.10429905816,
        0.10484294116000001,
        0.10472180316,
        0.10477673616000001,
        0.10417065616,
        0.10470080316000001,
        0.10480409816000001,
        0.10457502716,
        0.10485791916000001,
        0.10457604916,
        0.10470963016000001,
        0.10455243416,
        0.10453949016000001,
        0.10513959916,
        0.10457870416000001,
        0.10528667516000001,
        0.10480203416,
        0.10445526216,
        0.10474218116,
        0.10469200616,
        0.10483232116,
        0.10448696116
      ],
      "exit_codes": [
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0,
        0
      ]
    }
  ]
}

@KSXGitHub KSXGitHub closed this Mar 7, 2026
@KSXGitHub KSXGitHub deleted the copilot/address-pr-339-discussion-point branch March 7, 2026 20:05
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.

2 participants