I made some tests in GDI+ with drawing lines/arcs, on a graphics
class created .FromImage method.
For performance reasons, I divide this in a multithreading setup
(tests with several methods: New Thread(AddressOf.. or Parallel.For… or New Task..)
I have noticed that this gives no performance increase.
However if I am replacing the .Graphics.DrawPath routine by a test routine (for example: calculations) then there is a real improvement in performance when using multithreading
(see figures)
What is the reason for this and how to solve?
I have created four setups:
-
drawing on graphics:
4x (40000 elements on a seperate graphics.fromimage) on 4 threads (or task )
(time: 1s 76msec) -
drawing on graphics:
4x (40000 elements on a seperate graphics.fromimage) serial
(time: 959msec) -
calculation:
4x (floating point test calculation) on 4 threads (or task )
(time: 672msec) -
calculation:
4x (floating point test calculation) serial
(time: 2s 189msec
Any large library that’s thread-safe uses locks to protect shared state. These locks often cause contention between threads, a thread will get bogged down waiting for another thread to release the lock.
This is Ahmdal’s Law at work.