Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible declare optimize for a single package?

I am working on a project where I am happy with the vector package and wish to optimize it as much a possible without affecting the other packages that make up the project. I am aware that I can use the following inside a defun to optimize that single function

(declare (optimize (speed 3) (safety 0)))

and also that 'declaim' could be used to make the effect global.

Is there a way to optimize everything in a package or is it just safer to declare in each function?

[EDIT] Just a heads up to future readers: In almost all cases you do not want to use safety 0. Research this topic further before ever setting this in your code as you are opening yourself up to very system & implementation dependent bugs if you muck it up

like image 318
Baggers Avatar asked Feb 15 '23 22:02

Baggers


1 Answers

The extent of declaim is implementation dependent. In SBCL I think you may use with-compilation-unit to achieve what you want. However, I doubt the utility of this for performance purpose: most of the time performance critical code is concentrated on a very few places, and whatever gain you may have from the rest of the code is not worth the sacrifices of safety and debuggability.

like image 154
huaiyuan Avatar answered Mar 03 '23 06:03

huaiyuan