Playback speed
×
Share post
Share post at current time
0:00
/
0:00

Paid episode

The full episode is only available to paid subscribers of Computer, Enhance!

Q&A #55 (2024-05-20)

Answers to questions from the last Q&A thread.
15

In each Q&A video, I answer questions from the comments on the previous Q&A video, which can be from any part of the course.

Questions addressed in this video:

  • [00:03] “I'm curious if you have any insights on how useful database concepts such as data normalization can be applied not just to databases, but also to organizing the data in a codebase, and perhaps speeding it up?”

  • [03:20] “When optimizing, how do you split your time between algorithm gains and making the implementation faster?”

  • [06:17] “Do you ever use OpenMP? Thoughts on it?”

  • [06:21] “How do we compare the relative electricity consumption costs of different programs? I've seen a few talks that say generally, "Code Goes Faster => Code Uses Less Electricity", but we can't always use that rule of thumb to guestimate relative electricity cost.

    For example, suppose a non-vectorized loop that does barely any calculation is already memory bound. We can't gain a significant speed benefit by vectorizing the loop. Could vectorizing the loop still improve electricity consumption?”

  • [09:28] “I have a specific question regarding prefetching. Consider this scenario for using prefetch:'Vec' is a pointer to an array of size N, and 'idx' is an integer pointer storing a permutation of length N.

    We are going to access 'Vec' elements in a loop using Vec[idx[i]] (for i = 0; i <N; i++).

    The order of indices inside 'idx' can be arbitrary, so in a loop that reads 'Vec' elements according to 'idx', we're likely reading from random cache lines in each iteration.

    My questions are:

    Does prefetching help in this case?

    If so, in a loop that is constantly requesting the 'Vec' data and working (a bit on it) in each iteration, how early (or how many iterations back) should a prefetch for a certain index be issued?”

  • [14:10] “Since you don't use const in C++, do you also not pass temporary objects at all? Or is there another practical way to handle them?”

  • [16:00] “One is to make the internals a null terminated C style string, and that's it. The other would be to also store a string length. what option you would go for and the reasoning behind it?”

  • [18:43] “I remember a time I had a linked list of profiling data to go through and do some light processing and accumulate some data, and it was painfully slow. Sampler profiler indicated most time was spent on waiting for the first memory access on new elements. So I just tried adding a prefetch, and it was a huge gain. However, my boss said we could not use any prefetching as it was too unpredictable and was likely to give bad results in either case. So I had to remove it.”

The full video is for paid subscribers

Programming Courses
A series of courses on programming topics.