Recent

Author Topic: Questions on Multi-Thread Speed-Up and Efficiency  (Read 1116 times)

LeP

  • Sr. Member
  • ****
  • Posts: 437
Re: Questions on Multi-Thread Speed-Up and Efficiency
« Reply #15 on: June 26, 2026, 11:32:05 am »
I've found using multiple threads does not give me much of any increase of application performance because the OS just switches the threads and you still have the same processing time.......
Jamie

There's something wrong with the implementations. I can assure you that using threads is the best option for better performance (of course, if the application is developed properly).

I use them in all my application and not only some threads ... a lot of (near 30 or more) and tha major part of are manual managed.
Un Sistema per domarli, un IDE per trovarli, un codice per ghermirli e nel framework incatenarli.
An operating system to tame them, an IDE to find them, a code to catch them and in the framework chain them.

runewalsh

  • Full Member
  • ***
  • Posts: 130
Re: Questions on Multi-Thread Speed-Up and Efficiency
« Reply #16 on: June 26, 2026, 11:44:16 am »
Don't use "managed types" (dynamic array, ansistring, smart pointer). They all use interlocked instructions, and that slows down memory access for all threads.

Not really, this happens only under concurrency for the same variable (strictly speaking, cache line), and — surprise! — to some extent, even for regular (non-atomic) read-write accesses.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12948
  • FPC developer.
Re: Questions on Multi-Thread Speed-Up and Efficiency
« Reply #17 on: June 26, 2026, 12:43:23 pm »
Don't use "managed types" (dynamic array, ansistring, smart pointer). They all use interlocked instructions, and that slows down memory access for all threads. Even if each string/array was only used by a single thread (as you stated each thread has its own separate mem/data).

They use interlocked instructions shortly as spinlock to check the reference count. Not during the operations themselves. I don't expect this to be a very large effect.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12537
  • Debugger - SynEdit - and more
    • wiki
Re: Questions on Multi-Thread Speed-Up and Efficiency
« Reply #18 on: June 26, 2026, 01:32:25 pm »
Don't use "managed types" (dynamic array, ansistring, smart pointer). They all use interlocked instructions, and that slows down memory access for all threads. Even if each string/array was only used by a single thread (as you stated each thread has its own separate mem/data).

They use interlocked instructions shortly as spinlock to check the reference count. Not during the operations themselves. I don't expect this to be a very large effect.

dyn arrays indeed only on assignment of the array var, but not for elements.

AnsiStrings do check for copy on write. And (need to check the code), by the fact that even single threads occur human noticeable slowdown (compared to pchar) they may be doing that on every access to a char in them.

If he already is at the limits of his mem bandwitdth: the locked instructions affect caching. Other cores having a cacheline including the address need to reload that. So this can add into the overall bandwidth


EDIT: the slow down due to copy on write checks wouldn't be by the interlock. But they may be part of the execution, and then in threads they may cause more cache invalidates, leading to additional loads from RAM. (which may be few or many depending on exact code...)
« Last Edit: June 26, 2026, 02:07:34 pm by Martin_fr »

MathMan

  • Hero Member
  • *****
  • Posts: 530
Re: Questions on Multi-Thread Speed-Up and Efficiency
« Reply #19 on: June 26, 2026, 11:36:15 pm »
@all:

Some news from my side.

First news (good) - I'm an idiot! I totally ignored that my benchmarks are run on a laptop. If I also consider the CPU frequency adaptions I now see ~70-80% efficiency on 8 or 16 thread calculations in the assembler enhanced kernels. Even in a hughe calculation with memory footprint of ~1 Gbyte.

Second news (not so good) - after these very promising trials I now have to completely re-write my library  ;)

Thanks to all of you for your suggestions, literature recommendations, insights ...

creaothceann

  • Sr. Member
  • ****
  • Posts: 389
Re: Questions on Multi-Thread Speed-Up and Efficiency
« Reply #20 on: June 27, 2026, 08:41:15 am »
Yeah, making sure that the OS doesn't have a power-saving profile enabled can help too... ::)

 

TinyPortal © 2005-2018