Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Example of performance degradation due to the use of strict data constructors

I'm reading about strict data constructors. The linked Wiki article states that,

"strictness annotations can make performance worse [because] a strictness annotation forces the compiler to ensure that the field is fully evaluated before building the constructor, and if it turns out that the field was already evaluated then this is just wasted work".

I do not understand why if the field was already evaluated it is wasted work, since its value is needed anyway to apply the constructor.

Is there an example that illustrates this problem or other loses of efficiency due to strictness?

like image 357
Damian Nadales Avatar asked Jan 12 '17 21:01

Damian Nadales


People also ask

What are the factors that affect performance degradation?

The most prominent factors influencing degradation in steady-state operation are the current density and the operational temperature.

What is performance degradation?

Definition. Failure or degradation of a facility, process, system, or component that reduces the reliability of critical components of the facility whose loss or degradation prevents the system from performing its intended function.

What is computer performance degradation?

Originally Answered: Why does computer performance degrade? New software, software updates, viruses, fragmented harddrives, dust on the fans causing the hardware to work hotter, causing them to automatically slow down to save from themselves from melting.

Which technique is used to reduce network transmission degradation?

QoS is the technology that manages data traffic in order to reduce jitter on your network and prevent or reduce the degradation of quality. QoS controls and manages network resources by setting priorities by which data is sent on the network.


1 Answers

Forcing a value, even if it is already evaluated, has a small but existent cost.

If you have a pointer to something that might or might not be already evaluated (a thunk or a value), and you wrap it in a lazy data constructor, you just copy that address to its place in memory. That’s quick.

If you have such a pointer and you want to store it in a strict constructor, you have to evaluate it first. This requires checking the lowest bits of the pointer for possible tags (a trick to indicate evaluatedness). If no tag is present, you actually jump to this pointer to enter the thunk. Before you do that, you have to push an return frame onto the stack so that execution flow returns to you in the end. Then the thunk evaluates itself, puts the result in a register and jumps to the return address. Then you can put this result into memory.

So even if the thing you point to is already evaluated, you still have to do the tag check. And I believe in some cases evaluated things do not have a tag (it is optional), so all the other work might still happen – for nothing.

like image 162
Joachim Breitner Avatar answered Nov 15 '22 22:11

Joachim Breitner