jrmuizel / raqote

Rust 2D graphics library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non default blending modes are very slow

RazrFalcon opened this issue · comments

In my benchmarks, Screen is 2.5x slower than SrcOver and 15x slower than Screen by Skia.

This is somewhat related to #78

Can you share the benchmark you used to measure this?

Not yet, but they will be available in a few weeks. Roughly:

fn bench_raqote(c: &mut Criterion) {
    use raqote::*;

    let mut dt = DrawTarget::new(250, 250);

    let mut pb = PathBuilder::new();
    pb.move_to(10.0, 10.0);
    pb.cubic_to(20.0, 30.0, 120.0, 250.0, 200.0, 150.0);
    pb.close();
    let path = pb.finish();

    let src = Source::from(Color::new(200, 50, 127, 150));

    let draw_opt = DrawOptions {
        blend_mode: BlendMode::Screen,
        alpha: 1.0,
        antialias: AntialiasMode::None,
    };

    c.bench_function("fill screen raqote", |b| b.iter(|| {
        dt.fill(&path, &src, &draw_opt);
    }));
}

Nice. It's 4x faster now. Still 3.5x slower than Skia, but also 3.5x faster that cairo. Not sure why cairo is so slow.

PS: strangely enough, screen is now almost 2x faster than source over.

I get 94us for Screen and 74us for SrcOver. What do you see?

The measurements are way too random for some reason. Here are four consecutive runs:

test fill_raqote           ... bench:   2,168,547 ns/iter (+/- 216,760)
test fill_screen_raqote    ... bench:   2,012,489 ns/iter (+/- 17,217)
test fill_raqote           ... bench:   2,264,429 ns/iter (+/- 401,515)
test fill_screen_raqote    ... bench:   1,673,703 ns/iter (+/- 398,263)
test fill_raqote           ... bench:   2,770,236 ns/iter (+/- 112,410)
test fill_screen_raqote    ... bench:   1,166,555 ns/iter (+/- 15,600)
test fill_raqote           ... bench:   2,830,118 ns/iter (+/- 42,974)
test fill_screen_raqote    ... bench:   1,156,341 ns/iter (+/- 14,122)

I'm using bencher here.

Here is Skia and cairo for the reference:

test fill_cairo            ... bench:     251,161 ns/iter (+/- 4,435)
test fill_skia             ... bench:     287,226 ns/iter (+/- 2,898)

test fill_screen_cairo     ... bench:   4,179,952 ns/iter (+/- 52,633) (yeah...)
test fill_screen_skia      ... bench:     340,890 ns/iter (+/- 4,088)

They always produce the same results, unlike raqote.