Skip to content
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

Unbox small records #671

Open
raviqqe opened this issue Jan 22, 2022 · 2 comments
Open

Unbox small records #671

raviqqe opened this issue Jan 22, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@raviqqe
Copy link
Contributor

raviqqe commented Jan 22, 2022

Problem

  • We allocate memory blocks for records of any size unless they have no field.
  • Those extra heap allocations are sometimes expensive.

Solution

  • Unbox small records that have only a field of a size less than a word.
    • Those fields are all simple concrete types (i.e. non-union types.)
  • This is safe even for recursive types but might need some tweaks for a compiler.
    • For example, LLVM might complain about a self-recursive type of type foo { x foo }.
    • They can be represented as type foo { x usize } instead.
  • Do we want to change the FFI library too to implement easy-to-use new() constructors automatically.
    • They box or unbox records depending on a number of fields.

References

@raviqqe raviqqe added the enhancement New feature or request label Jan 22, 2022
@sammy-hughes
Copy link

sammy-hughes commented Feb 24, 2022

What about bigger primitives that aren't implemented by the language, such as complex numbers? Would such a target qualify for this optimization?

@raviqqe
Copy link
Contributor Author

raviqqe commented Feb 26, 2022

Thanks for your question!

What about bigger primitives that aren't implemented by the language, such as complex numbers?

It doesn't matter how big the primitives in the language are because this optimization is totally internal and not actually limited to small records but also applicable to any multi-word values. We can just box or unbox big primitives on demand at boundaries if necessary (e.g. to box big primitives into "variant" types or to make big primitives FFI-safe.)

Would such a target qualify for this optimization?

So yes!

But of course, data transfer between Pen and foreign languages like Rust is another topic on optimization!

mergify bot pushed a commit that referenced this issue Oct 13, 2022
- This reverts commit 1bbd8d2.
- Follow-up of #1033
- Part of #671
-
d01ddc8
- Close #444.

# Todo

- [ ] Unbox small records in FFI.
  - Search by `ffi::Arc<ffi::Any`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: Todo
Development

No branches or pull requests

2 participants