-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Vector example #131
Vector example #131
Conversation
The example is now done, though there are still bugs in the optimizer. Please let me know what you think; maybe some functions need to be simplified. |
I am currently looking at the optimizer bugs |
@mhyee I would love to know what happens if you run this with inlining. |
Rebased. Thanks to @o- for fixing the optimizer bugs. However, it looks like the example still needs #136. Inlining a large program like the vector is very, very slow. Running test_examples_long made me think I hit an infinite loop. I'm guessing that trying to prune the inlined program is the problem. Also, it's faster to optimize+run the program than it is to optimize, redirect the output to a separate file, and then run that file without an optimization pass. I'm guessing that reading in the file and parsing it takes a lot of time. Baseline
Inlining
After fixing up inlined.sou (removing extra output):
Inlining+constant folding
After fixing up inlined-cf.sou (removing extra output):
Then there's some bug, because there's a line:
Running the code directly after optimization is fine, because this line is in unreachable code. But redirecting it to output means it needs to be re-parsed, and this is a parsing error. |
I just now tried this example. Here are the numbers on my machine for comparison. Inline original program
Constant-fold inlined program
Inline then constant-fold original program
After inlining, the increase in code size is about - The number of inlinings performed = I used
I wonder if most time is spent parsing and disassembling code. |
Native compiler makes the vector example 3x faster, but it's still slow.
|
Looking at the result of inlining
This branch should be eliminated. Later:
This test can also be eliminated. This is precisely the sort of things that Jan mentioned early during the project: the code that gets produced by speculation/traces for a dynamic language tends to be very ugly, and simple optimizations can do a lot. I think it would be nice to do something here. |
Our first priority with regard to this PR is to find a way to merge it without making our testsuite explode. Ming-ho, could you just move this file to some other place than |
The same file also has (after inlining and constant-folding):
which suggests the cleanup passes should also be strengthened. (Note that what we can do here is strengthened by the enforced label invariants, we know that |
I renamed the file so it's not picked up by the test runner. Note that the test runner does not apply the I'll open a new issue to track these new optimization opportunities. |
It started as a vector example, but grew to encompass an object model and also a linked list.
Objects are implemented as a 2-array. The first cell is the type ID and the second cell is a reference to the object map, which contains all the fields and methods. Additional fields and methods can be added to an existing object.
For simplicity, the object map is implemented as a linked list. A growable array would have been more difficult to implement, and in fact, is already implemented as the example object. (I didn't want to implement it twice.)
The vector object consists of an array that doubles in size whenever it needs to be grown. It supports getting/setting, and later, a
map
function is added to the object.The example is thoroughly documented and tested. The optimized version runs fine and passes the tests. However, the optimized version fails due to bugs in the optimization passes, see #133.