Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Size Optimization: Capture root varaiable if it's a sharef ref #49

Open
arora-aman opened this issue Jun 16, 2021 · 2 comments
Open

Size Optimization: Capture root varaiable if it's a sharef ref #49

arora-aman opened this issue Jun 16, 2021 · 2 comments
Assignees
Labels
enhancement New feature or request

Comments

@arora-aman
Copy link
Member

arora-aman commented Jun 16, 2021

Initial thoughts:

  • If the root variable is a shared ref then any path starting at that root variable will be captured by ref or copied (in case the path is Copy and the closure is a move closure)

  • We will never have a borrow conflict if we reduce the precision

  • In the case where the path would've been captured by ref, truncating to the root variable and capturing the root variable will result in capture of the same size or maybe cheaper.

    • It's cheaper in case of function pointers. Right now the way preicse capture analysis would capture f: &F works is we caputre &*f which ends up capturing a fat pointer which is two words. Before precise capture we'd capture &f which is a thin pointer and a single word.
  • In the case where the path would've been copied, truncating to the root variable can possibly result increase in size compared to precise capture.

    • eg: Consider x: &T, x.y: u8 then it's cheaper to copy x.y is cheaper than copying x
@arora-aman arora-aman changed the title Size Optimization: Capture Root varaiable if it's a sharef ref Size Optimization: Capture root varaiable if it's a sharef ref Jun 16, 2021
@arora-aman arora-aman self-assigned this Jun 16, 2021
@arora-aman
Copy link
Member Author

arora-aman commented Jun 16, 2021

I kind of a had a side thought that I realize won't work, but want to document it as well.

A simpler way would be to just say that if the root variable is a shared ref,
a) If it's a non-move closure we capture the root variable
b) If it's a move closure we look through all precise captures and check if sum of the sizes is more than capturing the root variable and if true we capture the root variable.

Problem with this approach is we don't know the size of all types until we reach codegen (might need monomorphism).

@arora-aman
Copy link
Member Author

@arora-aman arora-aman added the enhancement New feature or request label Jun 22, 2021
@arora-aman arora-aman added this to the Polish complete milestone Jun 22, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant