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

Excessive stack allocation with multiple return points #19684

Closed
Aatch opened this issue Dec 10, 2014 · 4 comments
Closed

Excessive stack allocation with multiple return points #19684

Aatch opened this issue Dec 10, 2014 · 4 comments

Comments

@Aatch
Copy link
Contributor

Aatch commented Dec 10, 2014

This function uses ~1Kb of stack (with optimisations)

function test() -> [u8,...256] {
  let x : [u8, ..256];
  let val = get_val();
  if val == 0 {
    x = [1, ..256];
    return x;
  } else if val == 1 {
    x = [4, ..256];
    return x;
  } else {
    x = [9, ..256];
    return x;
  }
}

While this function uses ~256 bytes of stack:

function test() -> [u8,...256] {
  let x : [u8, ..256];
  let val = get_val();
  if val == 0 {
    x = [1, ..256];
  } else if val == 1 {
    x = [4, ..256];
  } else {
    x = [9, ..256];
  }

  return x;
}

As far as I can tell, each return statement gets given it's own slot which is copied into the return pointer at the end. This happens to also result in 4 memcpy calls in total.

/cc @gankro @cgaebel

@Aatch
Copy link
Contributor Author

Aatch commented Dec 11, 2014

Ok, found the issue. It was actually due to the check for nested returns being too conservative. I've got a fix in the works, just needs some polishing first.

@sinistersnare
Copy link
Contributor

ccme ( i wish there was a button i could push so i did not have to do this, sorry!)

@ftxqxd
Copy link
Contributor

ftxqxd commented Dec 11, 2014

@sinistersnare There is the ‘Subscribe’ button on the sidebar on the right, which makes you receive notifications from the issue. (I’m not sure if that behaves in exactly the same way as commenting, but I think it’s pretty similar.)

@sinistersnare
Copy link
Contributor

@P1start I already get emails from every thread (I subscribe by default), but by ccing I get the notification in the "participating" section, which is much easier to see than the torrent of other things going through this repo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants