jangko / nimPNG

PNG (Portable Network Graphics) decoder and encoder written in Nim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

This hash look up in calculateColorProfile is the slowest part of saving an image.

treeform opened this issue · comments

I have profiled nimPNG code saving with VTune and 45% of the time is spent on this line:

nimPNG/nimPNG.nim

Line 2358 in 676bca4

if not tree.hasKey(p):

This line is in calculateColorProfile ... should it just be computed once? It seems like a very slow operation with the hashing taking up most of the time. Is there a way to compute calculateColorProfile only once?

image

image

I used vTune with nim c -d:release --debugger:native to produce this.

Thank you, I think I know what's wrong with the hash function.

Amazing improvement, from the hottest function:

image

To being almost nothing:

image

Amazing!

Now the hottest path is the compression which is expected:

image