pharo-graphics / Alexandrie

FFI bindings and a 2D canvas for Pharo based on Cairo, Freetype and Harfbuzz
MIT License
5 stars 2 forks source link

Conversion from Cairo image to Form smells to be unnecessarily slow #44

Closed tinchodias closed 1 year ago

tinchodias commented 1 year ago

Profile:

| aSurface |
aSurface := AeCairoImageSurface
    extent: 16@16
    format: AeCairoSurfaceFormat argb32.
aSurface asFormARGB32

and get:

Screenshot 2023-11-22 at 22 35 48

We should check if it's true that FFIExternalArray >> resolveType takes 36.9ms (71% of total time!?)

tinchodias commented 1 year ago

The number of milliseconds was exaggerated in the output, I think, but the following results evidence resolveType: is significant:

| aSurface |
aSurface := AeCairoImageSurface
    extent: 16@16
    format: AeCairoSurfaceFormat argb32.
[aSurface asFormARGB32] bench.  
"164,764 iterations in 5 seconds 3 milliseconds. 32933.040 per second --> current"
"213,155 iterations in 5 seconds 1 millisecond.  42622.476 per second --> resolveType result hardcoded"

For the moment I will workaround with the hardcoded subclass that performs resolveType: on load, in class initialize.

tinchodias commented 1 year ago

Profiler now shows:

Screenshot 2023-11-22 at 23 43 16

I don't trust too much on this. But above's bench output makes me think 997fac0 does speedup a bit.