Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
![](/static/devrant/img/pipeless-devrant-banner-white.png)
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
sometimes parallization causes a huge syncronisation problem. The cost of sync outways that of the actual algorithm. Normally I use a single IO Thread and parallelize subtasks.
-
@MateTea42 in this case it's not the parallelization that fails to be optimized.
So I optimized a 40 second long process to run in 15 seconds by splitting it into 3 threads. But I added an overhead when making the code more readable, when I separated big operations into smaller ones, that allocated and freed a lot of memory.
I wanted pretty code, and that cost me more than any optimization would get back. -
... meanwhile I had failed to notice that at the same time as I started my 3 parallel worker threads, the CPU was already busy with other threads associated with the task, so I couldn't benefit from a full /3 time for that subtask.
Damn. When you've parallelized too much, you don't get anything extra from it. -
That is the problem with trying to optimize code. There are so many things you need to think about and one tends to always forget something.
-
@MateTea42 yeah. I reverted everything :P
There goes 1 day of work, down the drain. -
ddephor45137yMeasure and quantify before you optimize. Often the "obvious" things are not the real issue and you only waste your work optimizing the wrong spot.
-
@ddephor I did measure, and tried to optimize the bottleneck.
Not all things are bad. Some of the good stuff I had saved, and I gained 2% performance - yaaay :/ -
@perfectdark haha, I liked this gif so much that I bookmarked it. It perfectly illustrates my reaction in cases like this.
Related Rants
Hmmm, this feature that I added seems to make the whole process 50% longer. I need to optimize something. Let's see now...
Yeah, make that a shared resource and parallelize IO to leverage the multi-core architecture. Hash map for this, binary tree for that. This thing that gets called a million times can be written easily without a regexp. That thing can be rewritten in Rust as it's too demanding.
There! Works! And it's also a lot cleaner. Nice!
How's the performance doing? 70% longer.
undefined
fail
performance