I wrote some simple code to convert a RGB24 image represented as a []byte
to a NRGBA image (also as a []byte), like so:

https://play.golang.org/p/Y7ICg7t4_nd

Unfortunately, the performance is lacking here and I am trying to improve
it. The first low hanging fruit seems to be taking advantage of BCE:

$go test -bench .
goos: linux
goarch: amd64
BenchmarkNRGBA-8       484   2636344 ns/op

$ go test -gcflags="-B" -bench .
goos: linux
goarch: amd64
BenchmarkNRGBA-8       855   1654882 ns/op

Unfortunately, I could not find an incantation that would remove the bound
checks. My naive attempt was to just do

_ = nrgbaData[len(nrgbaData)-1]

at around line 7 in the program above but this did not help and added one
extra bound check.

Funny enough, if I do

_ = nrgbaData[len(nrgbaData)]

all the bound checks seem to be eliminated but, obviously, the program
panics at this line.

I am using

go build -gcflags="-d=ssa/check_bce/debug=1"

to check for the bound checks.

What am I missing here? Any suggestions on how to make this work?

And while we are at it, adding goroutines to convert partitions of the
image also helps (2 goroutines gives a 50% increase in performance more or
less). Other these 2 things, any other suggestion s0on how to make it
faster?

Thanks in advance.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/golang-nuts/CAEd86TzSSNfRrCV7ZhTf_KGo_dxKon2vxysghTeYDiMdFxp9sw%40mail.gmail.com.

Reply via email to