bksahu's Blog

Optimizing "map" and "zip" - Weekly check in #4

bksahu
Published: 07/15/2019

1. What did you do this week?

This week I started up with optimizing "map" built-in but later realised that I first need to optimize "zip" as there is no support on Nuitka for it as "map" is dependent on it. Initially I implemented the C backend for Python2 "zip" function but after discussing with my mentor we decided to keep only C backend for Python3 "zip" and depend on re-formulation for Python2 "zip" built-in.

2. What is coming up next?

Next up I will optimize zip for Python 3 and then get back to optimize "map" built-in.

3. Did you get stuck anywhere?

Well, I wouldn't say I was stuck anywhere but I had a lot of discussions on developing an optimization approach for the built-in mentioned above. 

 

Thanks!

Batakrishna

View Blog Post

Blog post #3

bksahu
Published: 07/07/2019

Hello everyone! Welcome to my 3rd blog post.

So, I am very happy to inform that I have passed my first evaluations with flying colors and now working on phase 2.

I learned a new way of optimization for Nuitka that doesn't need any CPython code replication. The idea is very simple i.e to build on top of existing nodes on Nuitka. Consider the following example, below is the optimization for min() built-in

makeStatementConditional(
    condition=ExpressionComparisonGt(
        left=ExpressionTempVariableRef(
            variable=min_result_variable, source_ref=source_ref
        ),
        right=ExpressionTempVariableRef(
            variable=min_arg_variable, source_ref=source_ref
        ),
        source_ref=source_ref,
    ),
    yes_branch=StatementAssignmentVariable(
        variable=min_result_variable,
        source=ExpressionTempVariableRef(
            variable=min_arg_variable, source_ref=source_ref
        ),
        source_ref=source_ref,
    ),
    no_branch=None,
    source_ref=source_ref,
)

The above is equivalent to (in Python):

min_result_variable if min_result_variable > min_arg_variable else None

In this way we can optimize reusing existing nodes. Now the only difficulty is in the case when there is more than one argument. Such type of problems are handled in Nuitka using something called reformulation. So, by using reformulation our problem will decomposed in to a simpler problem. For example:

min(1, 2, 3) ---(reformulation)---> min(min(1, 2), 3)

Hence, in this way we can optimize in an efficient way.

Thank you for stopping by! 
Batakrishna

View Blog Post

Optimizing "max" and "min" - Weekly check in #3

bksahu
Published: 07/02/2019

1. What did you do this week?

Finally I was successfully able to optimize the max and min built-in with my new understanding of Nuitka internals. Apart from that did some refactoring for my algorithm for BUILTIN_ALL optimization. It is almost ready to be merged to the main code base.

2. What is coming up next?

This is I will spend time on fixing bugs if any in the "abs", "min" and "max" optimization. Also, I will start with a new built-in optimization. 

3. Did you get stuck anywhere?

Nope, I didn't get stuck anywhere. 

View Blog Post

Blog post #2

bksahu
Published: 06/25/2019

Hello. Welcome to my second blog post.

The first evaluations have started. When I look back into last month, I realize that I have learnt a lot and grown into a better developer. So, I am glad that I'm a part of this program and organisation.

So, as discussed in the last blog post I am proud to inform that I have successfully created the IterationHandles module that take care of the iteration needs. And the best past about this module is that it is not limited to any() built-in optimization but can be reused in many other built-in optimizations as well. This module made my job very easy while optimizing "all" built-in.

abs() built-in optimization: While going through the original CPython implementations of this function I noticed that it is has a nb_absolute member which stores the absolute value of a variable, which means I had to manually add slots for every shapes (Eg. int, float). Now, this optimization needs a final touch up after review.

I am hoping to see those optimizations in next release.

Thank you for reading!

Batakrishna 

View Blog Post

Optimizing "abs" - Weekly Check-in #2

bksahu
Published: 06/19/2019

Welcome to my third weekly check-in!

1. What did you do this week?

This week I spent time on optimizing the "abs" built-in and understanding the "operators" module.

2. What is coming up next?

Next up, I will be working on adding support for "max" and "min" built-in after discussing potential optimizations with my mentors.

3. Did you get stuck anywhere?

Yes, I was stuck while implementing the "BUILTIN_ABS" CPython implementation for Nuitka. I have fixed it by doings the version checks.

 

Thank you for reading!

View Blog Post