Skip to content

Commit

Permalink
Update unboxing post
Browse files Browse the repository at this point in the history
  • Loading branch information
plajjan committed Sep 27, 2024
1 parent 5219a6b commit 4074c6a
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 7 deletions.
32 changes: 28 additions & 4 deletions content/blog/2024-05-unboxing.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@ date = 2024-05-05

# Unboxing Integers

When performance is key—whether it's large datasets or heavy computations—every millisecond counts. Acton’s new integer unboxing can speed up number-heavy applications by 10x or more. In this post, well break down what integer unboxing is, how it works, and why it matters for your performance-critical code.
Acton's new integer unboxing feature can speed up number-heavy applications by 100x or more. In this post, we'll break down what integer unboxing is, how it works, and why it matters for your performance-critical code.

**Boxed (yellow) vs Unboxed (green) vs Python (Yellow)**
[![](/blog/boxed-vs-unboxed.png)](/blog/boxed-vs-unboxed.png)

## Boxed values

Expand Down Expand Up @@ -72,9 +74,31 @@ double dctQ_U_5dct_sum (double U_6l) {
}
```
Which is pretty much as simple and optimal as one would write by hand. In other words, using Acton, which can certainly be considered a higher level language than C, comes with essentially no overhead for this program. The performance from boxed values to our first version of unboxing is roughly 10x and to unboxing v2 is roughly 10x and going from completely boxed to the current unboxing support is an even bigger improvement.
Which is pretty much as simple and optimal as one would write by hand, bar the naming convention. In other words, using Acton, which can certainly be considered a higher level language than C, comes with essentially no overhead for this program. Boxed values are doubly bad because they also exert a massive pressure on the memory subsystem, both when allocating on the heap and when the GC subsystem is collecting garbage. This makes a tremendous difference in performance, especially for larger values where memory consumption grows. With unboxing, we avoid the extra memory allocation and instead store values on the stack and pass them to functions via CPU registers.
## Conclusion
The introduction of integer unboxing in Acton is a game-changer for performance-intensive applications. By leveraging these optimizations, Acton developers can now write high-level code without sacrificing low-level performance. With up to a 10x speed boost for number-heavy programs, it's clear that Acton continues to evolve into a more powerful and efficient language. Whether you're working on image processing, data analysis, or any other performance-critical application, Acton's new integer unboxing support ensures that you're getting the most out of your hardware.
## Doubly good for the GC and memory subsystem
By not allocating memory for boxed values, we avoid the need for the garbage collector to clean up after them. This is a double win for performance, as the garbage collector can be a significant bottleneck in many applications. Acton currently uses the Boehm GC (but not for long!), which is a mark-sweep collector with a stop-the-world. All Acton Run Time System worker threads are stopped while running the GC which means that otherwise parallelizable code might not end up being very fast because we become concurrency constrained around GC. Using unboxed values avoids malloc & GC altogether and so our application can easily run concurrently.
## Performance comparison
In this graph we can see the performance difference between the boxed and unboxed versions of the DCT program. Depending on the input size, the unboxed version can be 100x or even faster. Python is also included in this comparison where it scores better than the boxed version but still significantly slower than the unboxed version.
**Boxed (red) vs Unboxed (green) vs Python (Yellow)**
[![](/blog/boxed-vs-unboxed-vs-python.png)](/blog/boxed-vs-unboxed-vs-python.png)
If we remove Acton's boxed version, we can zoom in on the unboxed and Python versions. Acton's unboxed version is, by quite a fair margin, consistently faster than Python, for all input sizes. The difference becomes more pronounced as the input size grows and at 10000, Acton is ~15x faster than Python.
**Unboxed (green) vs Python (yellow)**
[![](/blog/unboxed-vs-python.png)](/blog/unboxed-vs-python.png)
Many computationally intensive applications are written in C and receive a thin wrapper in Python or some other high level language. Now you can write the entire application in Acton and still get the performance of C!
## Future work
The current implementation of unboxing in Acton supports local variables and function arguments. In the future, we plan to extend this support to object and actor attributes as well. This will further improve the performance of Acton programs, especially those that rely heavily on object-oriented programming.
Further, monomorphization is a technique that can be used to specialize generic functions for specific types. This can be used to optimize the performance of functions that are called with a small number of different types. We plan to explore monomorphization in Acton to further improve the performance of generic functions.
Until then, enjoy the speed boost that unboxed integers bring to your Acton programs!
2 changes: 1 addition & 1 deletion content/blog/_index.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
+++
title = "List of blog posts"
title = "Posts"
weight = 8
sort_by = "date"
template = "blog.html"
Expand Down
Binary file added content/blog/boxed-vs-unboxed-vs-python.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/blog/boxed-vs-unboxed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added content/blog/unboxed-vs-python.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 0 additions & 2 deletions content/learn.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ weight = 2
template = "page.html"
+++

# Learn Acton

- [Acton Guide](https://acton.guide)
- [Acton tutorial](https://github.com/actonlang/acton/tree/main/docs/tutorial)

0 comments on commit 4074c6a

Please sign in to comment.