Previous | Next --- Slide 45 of 64
Back to Lecture Thumbnails
pufan

Actually, many modern compiler or data process optimizer or data pipeline scheduler, you name it, has ability to auto-fuse such kind of operations together. So you could keep your code neat as well as get good performance.

One example is Spark, with an optimization called delay running (something like that, I can't remember exactly), so it could merge these 'map-like' methods together to a bigger 'map-like' method.

lusiliang93

For the code on top, tmp1 are used to store the value in function of add and then the value of tmp1 is loaded again in the function of mul. Variable tmp2 has the same usage. However, for the code on bottom, only E is used to store the value and other variables are loaded at a time. The code on bottom could have better temporal locality since four loaded variables are referenced during each call of fused while the code top only load two variables during each call of add or mul.