On Sun, May 23, 2010 at 1:36 AM, Roland Mainz <[email protected]> wrote:
> Here is an old RFE which was sitting on my desk since a while:
> AFAIK it may be nice to add a -O flag to "shcomp" to enable some kind
> of optimisations which are usually to heavywheight during normal shell
> execution since they take too much time.
> For example these optimisations may be nice:
> - Remove unneccesary blanks in arithmetric expressions, e.g. $ print
> '(( sin( 5 ) ))' |
> shcomp >shbin # currently creates a larger execuitable than $ print
> '((sin(5)))' | shcomp >shbin # - the option -O should strip that
> - Convert static arithmetric expressions like 1+1 or sin(cos(5)) into
> integer or hexfloat strings and store these in the compiled shell code
> (goal is to reduce execution time).
> - String "peephole optimisations": Convert quoted strings like x\ b\
> i\ p\ z into a common, shorter form (like "x b i p z" or $'x b i p
> z'). This applies mainly to string literals which use weired quoting
> in shell scripts to cover multiple lines, don't know about $'...'
> literals or somehow else have weired intentions
> - Removal of line continuations: Line continutations with \ should be
> removed (to save space, LINENO should not be guranteed to be exact
> with -O)
> - Replace statements like "while true ; do" with "for ((;;)) ; do",
> assuming the 2nd form is a bit faster.
> - Use a "hardcoded" path for variable declarations like "float",
> "integer", "typeset" (plain string), assuming no value assignments
> happen and no extra options are set. Right now the whole code always
> goes through |b_typeset()| and calls very heavywheight functions like
> |ast_getopts()| each time. IMO shcomp -O should try to optimise this
> away (maybe by using extra special builtins to declare such variables
> without going through all the heavywheight code).
> - <insert more ideas>
>
> Any comments/ideas/suggestions ?
- Two more items:
1. Combine things like...
-- snip --
(( a+=1 )) ; (( b+=1 )) ; (( c=a+b ))
-- snip --
... to ...
-- snip --
(( a+=1 , b+=1 , c=a+b ))
-- snip --
The 2nd version is faster (as said LINENO does not have to be accurate
when -O is enabled).
2. AFAIK this may be worth to be optimised:
-- snip --
for((i=0 ; i < n ; i++ )) ; do
(( sum+=sin(i) ))
done
-- snip --
Since all operations happen in arithmetric mode it may be interesting
to just internally combine the whole things and execute it only in the
arithmetric engine (currently the code executes the
for((())-expression and the (( sum+=sin(i) )) expression seperately
and covers lots of non-airthmetric code between both).
----
Bye,
Roland
--
__ . . __
(o.\ \/ /.o) [email protected]
\__\/\/__/ MPEG specialist, C&&JAVA&&Sun&&Unix programmer
/O /==\ O\ TEL +49 641 3992797
(;O/ \/ \O;)
_______________________________________________
ast-developers mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-developers