18

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.

Comments
  • 2
    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.
  • 1
    @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.
  • 0
    ok that makes sense. btw did you fix the problem?
  • 1
    ... 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.
  • 1
    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.
  • 0
    @MateTea42 yeah. I reverted everything :P
    There goes 1 day of work, down the drain.
  • 1
    outch :/ my sympathies.
  • 3
    Measure and quantify before you optimize. Often the "obvious" things are not the real issue and you only waste your work optimizing the wrong spot.
  • 1
    @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 :/
  • 2
    Anyone else here just for the girl?
  • 2
    @perfectdark haha, I liked this gif so much that I bookmarked it. It perfectly illustrates my reaction in cases like this.
Add Comment