inner-conditional
2020-09-25
Series of macros which optimizes out the inner conditional jumping
1Inner-Conditional
- Series of macros which help users optimize the conditional jumps in a inner loop
- The interface is similar to the continuation, so I call it as `compile-time continuation’.Everything is implemented in compile-time so theres no performance drawbacks in run-time
- Extensible syntaxes and helper macros for other implementers of libraries, especially for the macro writers or the heavy lambda-lovers. Provides a standardized way to minimize the number of condition check
2Recent changes
- It does not use
macrolet
andsymbol-macrolet
anymore, which meansit can be used withiterate
library. (2013/5/3) - This library is not well maintained now. Please (?) don't use it.
- I think I will reerite it with recursive-macroexpansion.
3Basic Usage
The condition checking is done only once.
(ql:quickload :iterate)
(use-package :iterate)
(defun test0 (flag)
(with-inner (body)
(iter (for i from 0 to 5)
(print i)
(inner (body)
(if flag
(body (princ "loop on"))
(body (princ "loop off")))))))
INNER-CONDITIONAL-TEST> (test0 t)
0 loop on
1 loop on
2 loop on
3 loop on
4 loop on
5 loop on
4Concepts and API
Removing conditional jumps in loops are one of the easiest way to optimize the loop. The number of checks should be minimized, and the checking variables in a smaller loop may well be a large bottleneck. Yet, some code would yield a bad-looking result of that optimization, since the semantics of the code best fits the code which has conditional jumps in a smaller loop. Luckily, Common Lisp has macros, which provides the ability to walk on and modify the code tree. So we can keep the code clean and at the same time get a faster result.
For more details, see Concepts and API (https://github.com/guicho271828/inner-conditional/blob/master/concepts-and-api.org)
5Use with your own library
If you write a macro which expands to a code which always checks a certain dynamic variable then this library may help you write an extension which minimizes the number of checks in the expanded code.
For more details, see Use with your own library (https://github.com/guicho271828/inner-conditional/blob/master/use-with-your-own-library.org)
6Optimization Results
The effect of this library may seem trivial, but still I try to show you an optimization results with trivial examples. Any other result reports are welcome! Because I don't came up with other truly-performance-sensitive examples.
For more details, see Optimization Results (https://github.com/guicho271828/inner-conditional/blob/master/opt-results.org)
7Misc
7.1Dependencies
This library is at least tested on implementation listed below:
- SBCL 1.1.2 on X86-64 Linux 3.2.0-39-generic (author's environment)
Also, it depends on the following libraries:
- ITERATE
- Jonathan Amsterdam's iterator/gatherer/accumulator facility
- ALEXANDRIA
- Alexandria is a collection of portable public domain utilities.
- CL-ANNOT by Tomohiro Matsuyama
- Python-like Annotation Syntax for Common Lisp
- CL-SYNTAX by m2ym
- Reader Syntax Coventions for Common Lisp and SLIME
- Optima by m2ym
- Optimized Pattern Matching Library for Common Lisp
7.2Installation
- First grab the code with
git clone git://github.com/guicho271828/inner-conditional.git
- Put it in your local-project folder
- open slime REPL
(ql:register-local-projects)
(ql:quickload :inner-conditional)
and the library will beinstalled along with the dependencies
7.3Author
- Masataro Asai (guicho2.71828@gmail.com)
7.4Copyright
Copyright (c) 2013 Masataro Asai (guicho2.71828@gmail.com)
7.5License
Licensed under the LLGPL License.