News for hackers. Stuff that matters.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by reikonomusha on Thursday June 22, 2017 @11:02AM (#14612703)
One neat thing about Common Lisp is that you can specify compilation directives in an extremely granular way: per file, per function, and even in a scope-delimited fashion within a part of a function. You can do this with Lisp's DECLAIM, DECLARE, and LOCALLY DECLARE syntax respectively.

Compiler directives are given as numerical levels of speed, safety, compilation speed, code size, and debuggability. There are other more specialized directives beyond those.

If you're building a web app and the backend has 2 or 3 really hot code paths, you can do something like:

    (defun hot-path (request)
      (declare (optimize (speed 3) (safety 0) (debug 0)))
      ...)
This roughly reads: "For ONLY the function HOT-PATH, compile it only with execution speed in mind. Eliminate extra runtime checks like array bounds checking or overflow, because I have meticulously checked and proved that to not be an issue. While you're at it, don't mind how debuggable it is at runtime; don't record anything about the call or it's internal workings, perform tail call elimination, etc."

I'll usually abstract away the DECLARE with more semantically meaningful terms: OPTIMIZE-DANGEROUSLY-FAST, OPTIMIZE-FOR-SCRUTINY, etc.

In general, in Lisp, I would say it's even considered bad hygiene to flip the global optimization switch; as djb and the article say, most of your large programs don't need it. You also often sacrifice debuggability in the entirety of your program if you ask the compiler to do what it can to make it fast.

Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by greglindahl on Thursday June 22, 2017 @02:51PM (#14614404)
The problem with directives is not on day 1, they're awesome on day 1. The problem is usually that the directives are in the wrong place 10 years later.

Loop unrolling directives went through that process in just a few years, from giving a nice speedup, to compilers being able to mostly match the directive, to the directive causing slowdowns, to compilers ignoring that directive.

Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by fao_ on Thursday June 22, 2017 @08:04PM (#14616221)
... at which point you can edit a single point in the source code to fix it, either defining hot-path to be equivalent to eval, removing it outright, or altering it to be better. Isn't that the point of abstraction?
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by moomin on Friday June 23, 2017 @02:51AM (#14617429)
A misplaced directive is probably preferable to misplaced manual optimisation, though.
Re:What Challenges and Trade-Offs Do Optimising Compilers Face? by krylon on Friday June 23, 2017 @07:50AM (#14618472)
Amen, I wish more popular languages would choose a similar approach.