Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rotation of large images seems super slow. #20

Closed
Petah opened this issue Sep 6, 2016 · 3 comments · Fixed by #21
Closed

Rotation of large images seems super slow. #20

Petah opened this issue Sep 6, 2016 · 3 comments · Fixed by #21

Comments

@Petah
Copy link

Petah commented Sep 6, 2016

I was just trying a basic example:

package main

import (
    "github.com/anthonynsimon/bild/imgio"
    "github.com/anthonynsimon/bild/transform"
)

func main() {
    img, err := imgio.Open("PW2_8123.JPG")
    if err != nil {
        panic(err)
    }

    rotated := transform.Rotate(img, 90, nil)

    if err := imgio.Save("filename", rotated, imgio.PNG); err != nil {
        panic(err)
    }
}

And it took super long:

$ time ./main

real    0m26.787s
user    0m41.122s
sys 0m0.958s

The image is a 10mb photo.

@anthonynsimon
Copy link
Owner

Right now we are working on performance optimization and bug fixing as we head towards v1.0.0, so this is a good case to benchmark against.

Could you please tell me the dimensions of the image, and if possible the specs of the computer?

@anthonynsimon
Copy link
Owner

anthonynsimon commented Sep 6, 2016

I optimized the Rotate function for special angles (for ex.: 90, 180, 270...), as these angles don't need supersampling when rotating. Now it performs much faster.

benchmark                   old ns/op      new ns/op      delta
BenchmarkRotation256-8      7858767        876950         -88.84%
BenchmarkRotation512-8      29263657       4050521        -86.16%
BenchmarkRotation1024-8     119374673      15880952       -86.70%
BenchmarkRotation2048-8     466060630      89323900       -80.83%
BenchmarkRotation4096-8     2033882420     388791904      -80.88%
BenchmarkRotation8192-8     8476689250     1663045960     -80.38%

benchmark                   old allocs     new allocs     delta
BenchmarkRotation256-8      21             7              -66.67%
BenchmarkRotation512-8      21             7              -66.67%
BenchmarkRotation1024-8     21             7              -66.67%
BenchmarkRotation2048-8     21             7              -66.67%
BenchmarkRotation4096-8     21             7              -66.67%
BenchmarkRotation8192-8     21             7              -66.67%

benchmark                   old bytes      new bytes     delta
BenchmarkRotation256-8      4457292        524540        -88.23%
BenchmarkRotation512-8      17826589       2097424       -88.23%
BenchmarkRotation1024-8     71303960       8388876       -88.24%
BenchmarkRotation2048-8     285213464      33554698      -88.24%
BenchmarkRotation4096-8     1140851480     134218001     -88.24%
BenchmarkRotation8192-8     4563403544     536871168     -88.24%

Also I partly optimized the Resize function which is part of how supersampling is handled, so non-special angles should see a small performance increase. More optimizations should be made on that.

@Petah
Copy link
Author

Petah commented Sep 6, 2016

FWIW The image was 6000x4000. This was on a MBP, 2.2ghz, 16gb ram.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants