Recent

Author Topic: Performance Comparison on Accessing Bitmap Pixels  (Read 2554 times)

ADMGNS

  • New Member
  • *
  • Posts: 30
  • keep it simple and smart
Performance Comparison on Accessing Bitmap Pixels
« on: May 09, 2020, 01:19:43 am »
hello,

i,ve scratched a test app that query performance accessing bitmaps pixel..

here is:

https://tinyurl.com/ycbyqkwq

Q: i think, x64 compilers have some performance issues. how can we solve this problem ??

platform: win7, x64

thank you


winni

  • Hero Member
  • *****
  • Posts: 3197
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #1 on: May 09, 2020, 02:10:52 am »
Hi!

There is nothing to solve.

Look into the code of TBitmap - then you will understand.
It must be compatible to all OS.

I you want quicker bitmaps the have a look:

https://wiki.freepascal.org/Fast_direct_pixel_access

Winni

circular

  • Hero Member
  • *****
  • Posts: 4220
    • Personal webpage
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #2 on: May 09, 2020, 09:24:04 am »
Interesting measures.

It is very surprising indeed the difference with 64 bits. It is like 30 times slower.

What exactly are you measuring? Can you post your project as well?

Conscience is the debugger of the mind

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #3 on: May 09, 2020, 11:55:26 am »
What is the compiler version and what are the compiler settings?
fpc 3.2.0 and trunk contain many Intel X64 optimizations.
The compiler settings are also important, e.g. -CpCOREAVX2 and -CpCOREAVX2 can make a significat difference too.
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

ADMGNS

  • New Member
  • *
  • Posts: 30
  • keep it simple and smart
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #4 on: May 09, 2020, 01:08:53 pm »
Interesting measures.

It is very surprising indeed the difference with 64 bits. It is like 30 times slower.

What exactly are you measuring? Can you post your project as well?

hello,

project is there, pls check the link..

thank you

ADMGNS

  • New Member
  • *
  • Posts: 30
  • keep it simple and smart
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #5 on: May 09, 2020, 01:11:56 pm »
What is the compiler version and what are the compiler settings?
fpc 3.2.0 and trunk contain many Intel X64 optimizations.
The compiler settings are also important, e.g. -CpCOREAVX2 and -CpCOREAVX2 can make a significat difference too.

hello, i wil try..

but, all settings were the same while compiling/linking..

thank you

ADMGNS

  • New Member
  • *
  • Posts: 30
  • keep it simple and smart
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #6 on: May 09, 2020, 01:15:58 pm »
Hi!

There is nothing to solve.

Look into the code of TBitmap - then you will understand.
It must be compatible to all OS.

I you want quicker bitmaps the have a look:

https://wiki.freepascal.org/Fast_direct_pixel_access

Winni

hello,

i,ve already checked that page. i know these methots, but,  i,ve tried other fast access methots as well..

problem is about x64 compiling and maybe compilers..

thank you

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #7 on: May 09, 2020, 01:53:33 pm »
Code: Pascal  [Select][+][-]
  1.  imgTest.Picture.Bitmap.BeginUpdate();
  2.  
  3.     for k:=0 to Size-1 do
  4.     begin
  5.       if (bpp = 4) and (k mod bpp = 3) then continue; // alpha channel, don't touch
  6.       t := Byte(not p[k]);
  7.       if (k mod bpp = 1) then continue;  //BGRA   0:b, 1:g, 2:r, 3:alpha
  8.       p[k] := t;
  9.     end;
  10.  
  11.     imgTest.Picture.Bitmap.EndUpdate();

Really weird code. Looks like you are testing mod and continue operators :-) If you are gunning for speed, simply split the loops on BPP. E.g. for bpp=4

Code: Pascal  [Select][+][-]
  1. var p : pdword;
  2.  
  3.  for i:=0 to (size div 4)-1 do
  4.    p^:=(p^ and $FF000000) or ((not p^) and $FFFFFF);
  5. [/code
  6.  
  7. For odd bpp's you probably need to unroll the loops a few times.
  8.  
  9. Of course, for real serious stuff, you need to implement the above in SSE2 for 4 pixels at a time, or 8 for the AVX2 case.
« Last Edit: May 09, 2020, 02:08:59 pm by marcov »

Thaddy

  • Hero Member
  • *****
  • Posts: 14373
  • Sensorship about opinions does not belong here.
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #8 on: May 09, 2020, 02:02:05 pm »
What is the compiler version and what are the compiler settings?
fpc 3.2.0 and trunk contain many Intel X64 optimizations.
The compiler settings are also important, e.g. -CpCOREAVX2 and -CpCOREAVX2 can make a significant difference too.
Second one should read -OpCOREAVX2.
Option -Sv may also benefit graphics processing. As does -CfAVX2 sometimes.
« Last Edit: May 09, 2020, 02:03:53 pm by Thaddy »
Object Pascal programmers should get rid of their "component fetish" especially with the non-visuals.

ADMGNS

  • New Member
  • *
  • Posts: 30
  • keep it simple and smart
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #9 on: May 09, 2020, 10:32:28 pm »
Code: Pascal  [Select][+][-]
  1.  imgTest.Picture.Bitmap.BeginUpdate();
  2.  
  3.     for k:=0 to Size-1 do
  4.     begin
  5.       if (bpp = 4) and (k mod bpp = 3) then continue; // alpha channel, don't touch
  6.       t := Byte(not p[k]);
  7.       if (k mod bpp = 1) then continue;  //BGRA   0:b, 1:g, 2:r, 3:alpha
  8.       p[k] := t;
  9.     end;
  10.  
  11.     imgTest.Picture.Bitmap.EndUpdate();

Really weird code. Looks like you are testing mod and continue operators :-) If you are gunning for speed, simply split the loops on BPP. E.g. for bpp=4

Code: Pascal  [Select][+][-]
  1. var p : pdword;
  2.  
  3.  for i:=0 to (size div 4)-1 do
  4.    p^:=(p^ and $FF000000) or ((not p^) and $FFFFFF);
  5. [/code
  6.  
  7. For odd bpp's you probably need to unroll the loops a few times.
  8.  
  9. Of course, for real serious stuff, you need to implement the above in SSE2 for 4 pixels at a time, or 8 for the AVX2 case.

hello,

here, the focused problem is not using mod or continue; but also the problem is, under same conditions, x64 compilers are dramatickly getting slow. right?

thank you

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11452
  • FPC developer.
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #10 on: May 10, 2020, 01:43:10 pm »
here, the focused problem is not using mod or continue; but also the problem is, under same conditions, x64 compilers are dramatickly getting slow. right?

I see no reason for that to happen. So it might be something in the setup. (e.g. optimizations on on 32-bit but not on x64)

It is not a general problem.

jiaxing2

  • Full Member
  • ***
  • Posts: 164
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #11 on: May 10, 2020, 02:53:06 pm »
About the slow compiler, I don't know if Free Pascal also patched itself to mitigate recent Intel vulnerabilities but GCC definitely does. It's slower to compile, produces slower to run and consumes more memory binary. The binary size also increased.

GCC and Clang now include many sanitizers and mitigations for hardware vulnerabilities.

ADMGNS

  • New Member
  • *
  • Posts: 30
  • keep it simple and smart
Re: Performance Comparison on Accessing Bitmap Pixels
« Reply #12 on: May 10, 2020, 09:06:53 pm »
hello guys,

many thanks for your all valuable replies. i will do same tests on linux.

thank you

 

TinyPortal © 2005-2018