Recent

Author Topic: Windows GDI and Speed question - inline;  (Read 4116 times)

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Windows GDI and Speed question - inline;
« on: October 10, 2016, 12:19:02 pm »
Hi all,

- Windows GDI -

I'm currently working on some old foreign (Delphi) sources, under Lazarus.
There I found several code blocks that are redundant (fully the same code),

calling several
- FillRect()
- MoveTo()
- LineTo()
- DrawText()
etc. ...


I could put them into some plain pascal subfunctions (to reduce redundancy).
=> So with using inline; the FPC compiler should put the code inplace (I think ..?)

Does it eat up relevant system CPU time  if I do NOT use inline; with such subfunctions ?
« Last Edit: October 10, 2016, 12:20:53 pm by PeterX »
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7864
Re: Windows GDI and Speed question - inline;
« Reply #1 on: October 10, 2016, 12:32:59 pm »
Rule of thumb is that Inline is only increases speed when the routines to be inlined are relative short, and simple. It can work speed decreasing if too long procedures are inlined, specially in a otherwise relatively short loop.

And all these effects won't really be noticable unless you really get into hundreds of thousands or million times per second magnitudes. (like operating on every pixel in image analysis)
 
In case of doubt: don't inline or benchmark, and in time you'll get a feel for it.
« Last Edit: October 10, 2016, 12:35:46 pm by marcov »

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Windows GDI and Speed question - inline;
« Reply #2 on: October 10, 2016, 01:59:42 pm »
Rule of thumb is that Inline is only increases speed when the routines to be inlined are relative short, and simple.
Okay, these Windows API functions are definetly not short or simple.
I'll try. If painting doesn't make any difference, .. I will avoid inline;

Thanks for Your hints !
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

Bart

  • Hero Member
  • *****
  • Posts: 3602
    • Bart en Mariska's Webstek
Re: Windows GDI and Speed question - inline;
« Reply #3 on: October 10, 2016, 02:06:35 pm »
AFAIK inline is a request to the compiler to inline the code, but that request may not always be honoured.

Bart

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7864
Re: Windows GDI and Speed question - inline;
« Reply #4 on: October 10, 2016, 02:51:28 pm »
AFAIK inline is a request to the compiler to inline the code, but that request may not always be honoured.

True, but that is afaik mainly across unit divisions. Delphi even has hints for this.

circular

  • Hero Member
  • *****
  • Posts: 3084
    • Personal webpage
Re: Windows GDI and Speed question - inline;
« Reply #5 on: October 10, 2016, 03:18:15 pm »
As marcov says, inline functions need to be small.

Basically, not doing "inline" requires to:
- push some registers on the stack
- copy the values of parameters

This is not significant compared to drawing shapes. In fact calling functions can be very fast so that the use "inline" is rare unless you're doing low level programming.
Conscience is the debugger of the mind

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Windows GDI and Speed question - inline;
« Reply #6 on: October 10, 2016, 04:49:14 pm »
In fact calling functions can be very fast so that the use "inline" is rare unless you're doing low level programming.
Until now I only used inline; for small ASM functions.

Using functions for these GDI subjobs will make my code
smaller and easier to maintain.  :D
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job

circular

  • Hero Member
  • *****
  • Posts: 3084
    • Personal webpage
Re: Windows GDI and Speed question - inline;
« Reply #7 on: October 10, 2016, 06:06:00 pm »
Yes, you can definitely afford putting those into functions.  :)
Conscience is the debugger of the mind

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 7864
Re: Windows GDI and Speed question - inline;
« Reply #8 on: October 10, 2016, 06:07:11 pm »
and assembler is currently never inlined anyway

PeterX

  • Sr. Member
  • ****
  • Posts: 326
Re: Windows GDI and Speed question - inline;
« Reply #9 on: October 10, 2016, 09:21:27 pm »
and assembler is currently never inlined anyway
Oh ?

Something like that can't be "inlined" ?

Code: Pascal  [Select]
  1. function AsmFn( A, X: Extended):Extended; {$ifdef FPC}assembler;{$endif}
  2. {$ifdef FPC} {$ASMMODE intel} {$endif}
  3. asm
  4.         // do some intel style ASM operations ..
  5. end;
  6.  
(  I just saw, indeed I never tried on my asm functions ..  :o  )


But I did it on this one, for example  ( to appease the angry "Hints"-Ghost in Laz .. ) :

Code: Pascal  [Select]
  1. function PtrToInt( p:pointer):integer; {$IFDEF FPC}inline;{$ENDIF}
  2. begin
  3.   Result:= {%H-}PtrInt( p);
  4. end;
  5.  
usually using latest Lazarus release version
with Windows 10 at home
and Windows 7 on the job