Recent

Author Topic: [Solved] Slow calls to DLL ?  (Read 8867 times)

halmariane

  • New Member
  • *
  • Posts: 30
[Solved] Slow calls to DLL ?
« on: May 21, 2013, 07:07:41 pm »
Hi everybody

All right?  :)

I am one doubt about the speed of calls to DLL from Lazarus.

In my project i have one DLL developed in C/C++. I have made all portings of headers, function calls (cdecl) and more to Lazarus. Really it's complicated to translate C to Pascal from my experience (macros, pointers, variable pass ...).

Ok, all performs right. There is no problem but .....

1.- The functions called from Lazarus (the execution) are more slow than C.
2.- If I compile the same calls in C/C++ then the execution is fast. (one simple "for do begin end")

I think that the guilty of the slow execution of Lazarus is for the CDECL calling convention. I fact, Lazarus has to convert Register calls to Cdecl calls.

Is that right?, is this correct?

Regards



« Last Edit: May 22, 2013, 10:13:02 am by halmariane »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 10662
  • Debugger - SynEdit - and more
    • wiki
Re: Slow calls to DLL ?
« Reply #1 on: May 21, 2013, 08:25:14 pm »
Sounds unlikely...

Use -al to generate assembler from your pas, and check what is in there.

halmariane

  • New Member
  • *
  • Posts: 30
[Solved] Slow calls to DLL ?
« Reply #2 on: May 22, 2013, 09:00:33 am »
Sounds unlikely...

Use -al to generate assembler from your pas, and check what is in there.

Thank you Martin_fr (hello, how are you?.. long time ...)

I have recompiled with -al, and in fact, seems there is nothing wrong in the assembler code. The calls to the library and the loading of parameters are made in a few instructions.
Code: [Select]
leal -44(%ebp),%eax
pushl %eax
leal -40(%ebp),%eax
pushl %eax
movl $_$UMQTT$_Ld5,%eax
pushl %eax
movl -8(%ebp),%eax
pushl 1164(%eax)
movl U_$MQTTCLIENTLIBRARY_$$_MQTTCLIENT_PUBLISHMESSAGE,%eax
call *%eax
addl $16,%esp
movl %eax,-48(%ebp)
cmpl $10,-52(%ebp)
jl .Lj188

After testing that the problem is not the "slow calls to DLL" I did more investigations.

 :-[
Looking differences in my code between C - Pascal.... I did not realized that  i forgot to set one parameter in the Pascal Code.

 :-[
Now the calls are as faster as C/C++

Thanks and regards
« Last Edit: May 22, 2013, 10:12:44 am by halmariane »

cwlyj001

  • New Member
  • *
  • Posts: 23
Re: [Solved] Slow calls to DLL ?
« Reply #3 on: February 03, 2024, 11:27:45 am »
I have encountered similar problems recently.

Under arm64 Linux, Lazarus free Pascal calls the fmpeg C dynamic library to complete the CPU decoding of H264. The decoding speed is very slow, and it actually takes 70 milliseconds to decode one frame. May I ask everyone, where is the problem? Calling C dynamic library under arm64 for free Pascal should be a regular operation, right

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11984
  • FPC developer.
Re: [Solved] Slow calls to DLL ?
« Reply #4 on: February 03, 2024, 11:59:43 am »
Yes, so that is not it.  The problem must be something else. Setting some quality parameter in the library or so.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: [Solved] Slow calls to DLL ?
« Reply #5 on: February 03, 2024, 12:08:10 pm »
70 milliseconds ! Are we really talking about 70 milliseconds?
70 milliseconds is approximately 0.07 seconds. So, 70 milliseconds is about 7% of a second.
I do not understand where the problem is about such low value.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

dseligo

  • Hero Member
  • *****
  • Posts: 1443
Re: [Solved] Slow calls to DLL ?
« Reply #6 on: February 03, 2024, 05:47:47 pm »
70 milliseconds ! Are we really talking about 70 milliseconds?
70 milliseconds is approximately 0.07 seconds. So, 70 milliseconds is about 7% of a second.
I do not understand where the problem is about such low value.

You didn't read his post carefully. His says that 70 ms is for "one frame" and decoding H264, so it is obvious he's talking about decoding video. If frame rate is 25 frames per second that 70ms times 25 becomes 1750 ms, which is about 175% of a second. Do you understand now where the problem is? :D

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: [Solved] Slow calls to DLL ?
« Reply #7 on: February 03, 2024, 06:27:22 pm »
70 milliseconds ! Are we really talking about 70 milliseconds?
70 milliseconds is approximately 0.07 seconds. So, 70 milliseconds is about 7% of a second.
I do not understand where the problem is about such low value.

You didn't read his post carefully. His says that 70 ms is for "one frame" and decoding H264, so it is obvious he's talking about decoding video. If frame rate is 25 frames per second that 70ms times 25 becomes 1750 ms, which is about 175% of a second.
I did paid attention about what he told, thank you for that upscaled math  :D
Do you understand now where the problem is? :D
No. 70ms to decode a single frame is good! The H264 codec does not store single images, the part of the frame within the fps region must be build from earlier frames up and rendered.
So again, where exactly is the problem?
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

cwlyj001

  • New Member
  • *
  • Posts: 23
Re: [Solved] Slow calls to DLL ?
« Reply #8 on: February 04, 2024, 04:37:55 pm »
I want to create a topic and upload a demo, but how do I create a new topic?

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: [Solved] Slow calls to DLL ?
« Reply #9 on: February 04, 2024, 04:44:51 pm »
I want to create a topic and upload a demo, but how do I create a new topic?
Prepare a demo in a minimalistic way, do not add binaries, this site has a low Filesize limit.
You look in the main directory of this forum for a matching subforum
-> https://forum.lazarus.freepascal.org/index.php?action=forum
Exemplary "Packages and Libraries"
-> https://forum.lazarus.freepascal.org/index.php/board,42.0.html
When you found a matching subforum press on the button that I show
« Last Edit: February 04, 2024, 04:47:52 pm by KodeZwerg »
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

Thaddy

  • Hero Member
  • *****
  • Posts: 16331
  • Censorship about opinions does not belong here.
Re: [Solved] Slow calls to DLL ?
« Reply #10 on: February 04, 2024, 04:48:09 pm »
I believe there is a required minimum of posts..
Just expand on this thread and attach your problem code.

@KodeZwerg
Oh and btw, 70ms makes a great difference in near real-time audio for example. The perceived audio latency is around 25 ms and should be lower to process audio in real-time.
It would make all my VST plugins useless. E.g. for ASIO the lag should not be more than 4ms for raw audio and up to a max of about 10-14ms with effects processing.
« Last Edit: February 04, 2024, 04:50:37 pm by Thaddy »
There is nothing wrong with being blunt. At a minimum it is also honest.

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Re: [Solved] Slow calls to DLL ?
« Reply #11 on: February 04, 2024, 04:57:56 pm »
@KodeZwerg
Oh and btw, 70ms makes a great difference in near real-time audio for example. The perceived audio latency is around 25 ms and should be lower to process audio in real-time.
It would make all my VST plugins useless.
What has playback to do with extraction of frames? When I want to playback something, I do not decode single frame by frame, I use proper codec for playback and that does not decode each frame, it just decode changed parts of a whole. There are not 25 pictures in a 25fps encoded stream, but a chance of 25 changed small parts within a second from a base image and that technique is not limited to 1 second, that why the "compression" is quit good.
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

cwlyj001

  • New Member
  • *
  • Posts: 23
Re: [Solved] Slow calls to DLL ?
« Reply #12 on: February 04, 2024, 04:58:42 pm »
@Thaddy, you are right. I really didn't see "new topic". I am ready to post under this topic.

cwlyj001

  • New Member
  • *
  • Posts: 23
Re: [Solved] Slow calls to DLL ?
« Reply #13 on: February 04, 2024, 05:19:15 pm »
This demo contains libraries for ffmpeg and sdl2, and can run normally on Win64 and Arm64. I must spend some time dealing with these before uploading. It should be tomorrow.

cwlyj001

  • New Member
  • *
  • Posts: 23
Re: [Solved] Slow calls to DLL ?
« Reply #14 on: February 05, 2024, 09:50:40 am »
The entire demo consists of three parts:

1. project source code (main.zip)

2. Ffmpeg and sdl component package (component.zip)

3. Ffmpeg and sdl dynamic libraries (ffmpeg_sdl2_library.zip)

please pay attention to downloading FTP://1: Test1234@121.40.151.139/

 

TinyPortal © 2005-2018