Boojay bytecode optimisation of loop

13 views
Skip to first unread message

James Caska

unread,
Sep 1, 2014, 7:02:54 PM9/1/14
to boo...@googlegroups.com
Hi,

I been evaluating using Boo/Boojay as the entry language of choice for highly resource constrained embedded microcontrollers ( 8-bit)

The loop function is both often used and often critical performance for these types of applications

I am new to Python/Boo and while I can see the value of the range() function it's orders of magnitude slower than the tight equivalent loop 


// print numbers from 0 until 9
for i in range(0, 10):
    print(i)

it is equivalent to

for (int i = 0; i < 10; i++) 
    // print

What would the risks be to the language if I changed the byte-code generation of this pattern to be the same as what javac would produce either in boojay or as a bytecode peephole optimisation of the boojay generated bytecode.

Could you recommend a way to indicate this pattern could be safely optimised? maybe a special keyword ?

ie (something like)

for i in finalrange(0,10):
    print(i)
     

Thanks! 
James Caska
www.virtualbreadboard.com

Rodrigo B. de Oliveira

unread,
Sep 2, 2014, 8:08:04 AM9/2/14
to boo...@googlegroups.com
Hi James,

As long as you're detecting that exact pattern there would be no risks.

One approach could be to insert a check for the exact version of the
range method you want to generate optimized code for somewhere close
to https://github.com/bamboo/boojay/blob/master/src/Boojay.Compilation/Steps/NormalizeIterations.boo#L21

and proceed to emit the required ast with CodeBuilder.

https://github.com/bamboo/boojay/blob/master/src/Boojay.Compilation/Steps/NormalizeIterations.boo#L27
should give you an idea on how to detect the method.

Best wishes,
Rodrigo
> --
> You received this message because you are subscribed to the Google Groups
> "boojay" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to boojay+un...@googlegroups.com.
> To post to this group, send email to boo...@googlegroups.com.
> Visit this group at http://groups.google.com/group/boojay.
> For more options, visit https://groups.google.com/d/optout.

James Caska

unread,
Sep 3, 2014, 6:36:36 PM9/3/14
to boo...@googlegroups.com
Thanks for the response.

I am still in two minds to make it a code generator or peephole bytecode optimsation. It will depend I think on how many optimisation I want to make.

The integration tests I have been using as unit tests and am about half way through compiling to java and running on my embedded JVM. A very useful suite..

So far I am looking at compiler flag options for range(constant) and negative indexes but  I will hold judgement on how I will go about it until I have got through the rest of the test suite.

I would also like to investigate changes to the static analysis to make it a compiler flag option to use a 16-bit integer and 32 bit long. ie for constant loading bytecode and signature options etc. 

This would have to be done in the code generator but it would be very useful for what I am working toward.

So-far Boo/Boojay have surpassed  expectations, very nice work!

Regards,
James Caska



James Caska

unread,
Sep 25, 2014, 12:23:46 PM9/25/14
to boo...@googlegroups.com
I looked into the code sections you suggested but I think the actual pattern seems to be generated on the Boo side.

In the end I optimised it on my compiler side as a peephole optimisation.

Reply all
Reply to author
Forward
0 new messages