Skip to content

Conversation

@sxyazi
Copy link
Owner

@sxyazi sxyazi commented May 1, 2025

See #2681

Closes #2681


This PR replaces the existing neural network quantization algorithm with Wu's Color Quantizer, which offers better performance while maintaining comparable quality.

I've integrated the new algorithm into Yazi's Sixel encoding process, and the benchmark has shown that the speed is 9 times faster than before.

Old implementation (neural network via color_quant, with highest quality sixel_fraction = 10) – average 226.2241541ms:

time: 226.126833ms
time: 225.860917ms
time: 226.056333ms
time: 225.696666ms
time: 225.801125ms
time: 224.998583ms
time: 226.203292ms
time: 226.440292ms
time: 228.368667ms
time: 226.688833ms

Old implementation (neural network via color_quant, with default sixel_fraction = 20) – average 189.5763999ms:

time: 190.025ms
time: 191.054417ms
time: 187.696792ms
time: 188.060791ms
time: 189.381958ms
time: 191.618042ms
time: 192.383125ms
time: 190.511291ms
time: 187.8395ms
time: 187.193083ms

Old implementation (neural network via color_quant, with highest speed sixel_fraction = 30) – average 175.1113751ms:

time: 175.640791ms
time: 175.352625ms
time: 175.085ms
time: 174.295667ms
time: 174.981209ms
time: 174.384667ms
time: 175.167667ms
time: 175.151208ms
time: 175.374167ms
time: 175.68075ms

New implementation (Wu - sRGB via quantette) – average 20.9199916ms:

time: 21.226458ms
time: 20.719542ms
time: 21.207583ms
time: 20.815875ms
time: 21.071291ms
time: 21.273459ms
time: 20.811792ms
time: 20.723166ms
time: 20.52675ms
time: 20.824ms

Benchmark script:

// yazi-adapter/src/drivers/sixel.rs
mod tests {
  use super::*;

  #[tokio::test]
  async fn test_sixel() {
    yazi_shared::init();
    yazi_config::init().unwrap();

    let img = image::ImageReader::open("/tmp/test.jpg").unwrap().decode().unwrap();

    for _ in 0..10 {
      let img = img.clone();

      let now = std::time::Instant::now();
      _ = Sixel::encode(img).await.unwrap();
      println!("time: {:?}", now.elapsed());
    }
  }
}

Then run the test in release mode:

cargo test --package yazi-adapter --lib --profile release -- drivers::sixel::tests::test_sixel --exact --show-output

With:

test

⚠️ Breaking changes

The sixel_fraction config option has been removed, as it was specific to the old neural network algorithm and is no longer needed in the new implementation.

@sxyazi sxyazi merged commit 9037f8b into main May 1, 2025
6 checks passed
@sxyazi sxyazi deleted the pr-8116b6ba branch May 1, 2025 16:47
sxyazi added a commit to yazi-rs/yazi-rs.github.io that referenced this pull request May 28, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 1, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Explore alternative color quantization algorithms

2 participants