Does sbcl consider whether a function has side-effects when optimizing?
Asked Answered
L

1

7

I have recently been reading the SBCL User Manual and started wondering about the title question. Obviously some lisps, for example clojure, ban all side effects so they can easily parallelize the code. Common Lisp allows side effects and so I was wondering if the fact a given function is 'dirty' or 'clean' affects it's compilation.

For example in the CMUCL compiler manual let optimizations show how, in many casesm the use of 'let' to bind a new variable will be more efficient than modifying with 'setq'. I guess I'm asking if something similar is done for function calls.

I have read the relevant sections of the sbcl manual and poured through the question on stackoverflow but could not find an answer to this.

Lenette answered 15/7, 2013 at 9:19 Comment(6)
Clojure doesn't (can't) ban all side effects. For example (println "Hello World") is a side effect. To ban them entirely they either need to 1. Not be in the language. 2. Be separated by a very strong type system. Anything else would mean the halting problemAntlion
Thanks, I should have made that clearer.Lenette
Write in to the sbcl-devel mailing list with your question. I am sure they will give you a good answer if you shoot them a good & clear question.Palaeontology
@PaulNathan: Cheers I'll go read some more and then probably do that.Lenette
@Lenette If your question was answered, please post it as an answer to this question.Wainscoting
Sorry, no this was a curiosity and I didnt look further into it. I will probably just start reading the compiler when it comes to me needing to know. CheersLenette
S
1

short: Not faster. Sometimes actually slower.

long:

According to Stas Boukarev from SBCL-devel,

SBCL doesn't even know that a function has no side effects, so, no. Besides, most of the time having side effects is the most optimal way.

I am aware of the fact that functions such as nreverse, which are destructive, tend to be faster than nondestructive functions (in this case reverse is the nondestructive version). They also come with many setbacks. As Peter Siebel put it:

Each recycling function is a loaded gun pointed footward.

Stancil answered 21/1, 2016 at 23:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.