Click here to Skip to main content
14,358,511 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.
 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 5:20
memberhoney the codewitch12-Sep-19 5:20 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Member 798912212-Sep-19 5:20
memberMember 798912212-Sep-19 5:20 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 5:23
memberhoney the codewitch12-Sep-19 5:23 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Member 798912212-Sep-19 7:15
memberMember 798912212-Sep-19 7:15 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 8:17
memberhoney the codewitch12-Sep-19 8:17 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Member 798912212-Sep-19 10:37
memberMember 798912212-Sep-19 10:37 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 11:58
memberhoney the codewitch12-Sep-19 11:58 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Member 798912212-Sep-19 14:37
memberMember 798912212-Sep-19 14:37 
dotNET is neither a compiler, an instruction set nor a machine architecture. (For the last one: Contrary to e.g. P4 or JVM.) It is like the specification of the interface in the gcc compiler suite between the (programming language dependent) front end and the (cpu architecture dependent) back end. "Like" is not in a "somewhat simillar to, in a rough sense", but rather like "an alternative competing directly with the gcc intermediate format for solving exactly the same set of problems". The backend exists in .net exactly as in gcc: CPU architecture dependent code is generated when the code is first loaded into the machine, and cached for later use.

Do you ever "blame" the intermedate gcc format for front ends that doesn't optimize the code much? That's what you do with dotNET. Put the blame where it deserves to be put.

I haven't studied the source code of a single compiler for the intermediate code of neither gcc nor dotNET. Maybe they don't do even the very simplest optimizations. Why not? Most techniques have been known for more than fifty years. I may suggest that they make a tradeoff: Compile time is far more essential with an interactive IDE than in the days when you submitted a card deck for compilation and picked up the compiler listing hours earlier. So we can't spend time on optimizations while the developer is impatiently twiddeling their thumbs waiting for the compilation to complete. Execution time is far less essential today - CPUs are fast enough! Optimizing for space is almost meaningless: Adding another 16 GiByte of RAM costs almost nothing, so why delay compilation to avoid that?

To some degree, they are right. And also: Modern pipelined CPUs reduces drastically the benefit of shaving off a few instructions from a linear sequence, compared to a hardcoded RISC CPU where every instruction (ideally) requires one clock cycle. Some of the old optimization techniques can safely be left out, as they have no measurable effect at all, given today's hardware.

Example, although not from compilers: Remember the "interleaving factor" when formatting DOS disks? If logical disk blocks 0, 1, 2... were physically laid out at sectors 0, 2, 4..., then you could read an entire track in only two disk revolutions. If you laid them out at sectors 0, 1, 2..., after reading sector 0, sector 1 passed the disk head while the controller was still stuffing away the data from sector 0. So it had to wait until sector 1 came around next time, a full revolution later. Reading an entire track, when interleaving was not applied, could require as many disk revolutions as the track had sectors. It must be 25+ years since the retirement of the last disk benefiting from interleaving.

Actually, Univac 1100-series compilers used a similar interleaving for data: When a word is read from memory, that entire row must be refreshed before it can be read again. So, consecutive locations were allocated cyclically in a set of rows: If you traverse an array sequentially (which is quite common), you skip from row to row, and when you cycle back to the first one, it has had plenty of time to refresh. With three cache levels in the CPU, and integral refresh logic, such optimization in the compiler is meaningless.

I did quite a lot of timing, from a programer's point of view, when I was working for a company making their own CPUs (this was in the "supermini" era), talking directly with the CPU designers. That's when I first learned the unimportance of the length of linear sequences, the effects of pipelining and interrups invalidating the pipeline. I also saw them remove a handful "optimizing" hardware features: They turned out to have microscopic effect but made the CPU significantly more complex, making it difficult to achieve a general speedup.

A more recent example: I made a small Soduko-solver to illustrate backtracking for a colleague, counting how many times I try to place a digit, testing if it is viable. The loop contains 13 C# statements: 3 if-statements, 6 one-dim array indexing operations, 2 two-dim array indexing operations, one of two alternate function calls..., plus the for loop control. One iteration of this loop takes around 30 nanoseconds. How much below 30 ns could I squeeze it by hand optimizing those 13 statements? Not that much. The worst puzzle I have found, requiring more than 57 million test loop iterations, complete in 1.8 seconds; there is no hard "user level" requirement for further optimzation!

So: I rarely study the instruction sequence generated, claiming that "I could have removed four instructions from that linear sequence". Rather, I do timing at application level, to see the real improvements in execution speed. Often, they are not possible to measure. Sometimes they are negative. Sometimes I am tempted to look at the generated code to see how it can be possible to run those 13 sudoko-solver C# statements in 30 nanoseconds...
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 14:40
memberhoney the codewitch12-Sep-19 14:40 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Alister Morton12-Sep-19 5:42
memberAlister Morton12-Sep-19 5:42 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
TrinityRaven12-Sep-19 5:47
memberTrinityRaven12-Sep-19 5:47 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 5:52
memberhoney the codewitch12-Sep-19 5:52 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
TrinityRaven12-Sep-19 6:23
memberTrinityRaven12-Sep-19 6:23 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 6:54
memberhoney the codewitch12-Sep-19 6:54 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Member 798912212-Sep-19 7:50
memberMember 798912212-Sep-19 7:50 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
TrinityRaven12-Sep-19 8:46
memberTrinityRaven12-Sep-19 8:46 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Member 798912212-Sep-19 11:13
memberMember 798912212-Sep-19 11:13 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Bruce Greene12-Sep-19 5:51
memberBruce Greene12-Sep-19 5:51 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Ira Greenstein12-Sep-19 6:07
memberIra Greenstein12-Sep-19 6:07 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Member 798912212-Sep-19 7:52
memberMember 798912212-Sep-19 7:52 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Ira Greenstein12-Sep-19 9:11
memberIra Greenstein12-Sep-19 9:11 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Roger House12-Sep-19 9:05
memberRoger House12-Sep-19 9:05 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
honey the codewitch12-Sep-19 9:07
memberhoney the codewitch12-Sep-19 9:07 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
Member 798912212-Sep-19 10:40
memberMember 798912212-Sep-19 10:40 
GeneralRe: do any of you others have little coding mantras that save your behind? Pin
firegryphon12-Sep-19 10:26
memberfiregryphon12-Sep-19 10:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.