Skip to content

Mitigate #2924 #3076

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

Merged
merged 2 commits into from
Sep 6, 2017
Merged

Conversation

nicolasstucki
Copy link
Contributor

To make the stack shorter we implement foldRightBN with
a foldLeftBN which allocates only half of the closures.
By doing so we need to eagerly reverse the list which is
in most cases small or empty.

To make the stack shorter we implement foldRightBN with
a foldLeftBN which allocates only half of the closures.
By doing so we need to eagerly reverse the list which is
in most cases small or empty.
@nicolasstucki
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

dottybot commented Sep 6, 2017

performance test scheduled: 1 job(s) in queue.

@dottybot
Copy link
Member

dottybot commented Sep 6, 2017

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3076 to see the changes.

Benchmarks is based on merge(s) with master

case x :: xs1 => fold(xs1, op(x, acc))
case Nil => acc
}
fold(xs, acc)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be

final def foldLeftBN[U](acc: => U)(op: (=> U, T) => U): U = {
  ...
  case x :: xs1 => fold(xs1, op(acc, x))

That's what I meant by "accumulator is the first arg of the closure"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is right, but if I do that the op must be put in another closure to reverse the parameter order.
I will make fold an inner method of foldRightBN and avoid this altogether.

@nicolasstucki
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

dottybot commented Sep 6, 2017

performance test scheduled: 1 job(s) in queue.

@dottybot
Copy link
Member

dottybot commented Sep 6, 2017

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3076 to see the changes.

Benchmarks is based on merge(s) with master

@nicolasstucki
Copy link
Contributor Author

While executing vulpix run tests, foldRightBN is mostly called on lists of size 0 and 1. This does not count the recursive calls that would have been in the original implementation.

size->invocations
0->1111034
1->1081070
2->142603
3->44560
4->19410
5->8234
6->5164
7->2277
8->1635
9->963
10->789
11->542
12->433
13->292
14->239
15->198
16->214
17->159
18->177
19->153
20->199
21->178
22->145
23->93
24->27
25->35
26->150
27->27
28->27
29->7
30->28
31->24
32->24
33->3
35->9
36->9
37->5
39->9
40->2
43->5
45->7
46->28
49->38
51->3
52->31
53->4
54->5
56->3
57->7
58->7
61->3
62->14
65->7
67->2
69->5
70->7
73->3
79->3
86->7
95->3
109->14
111->7
164->3
453->7
523->3
1424->7

@allanrenucci
Copy link
Contributor

LGTM

@allanrenucci allanrenucci merged commit c071dcf into scala:master Sep 6, 2017
@biboudis
Copy link
Contributor

biboudis commented Sep 6, 2017

@allanrenucci I was going to write on my review that we may need an extra test case. :-) Yesterday, we discussed with @nicolasstucki, that maybe an extra test would be needed to stress test this, but if it unblocks the CI then it is ok.

@allanrenucci
Copy link
Contributor

@biboudis This does not solve the core issue but mitigates it. @nicolasstucki will try to solve the core issue. We can include the test case in the next PR.

I merged this one to unblock some CI builds.

@biboudis
Copy link
Contributor

biboudis commented Sep 6, 2017

👍 👍

allanrenucci added a commit that referenced this pull request Sep 6, 2017
@allanrenucci allanrenucci deleted the improve-foldRightBN branch December 14, 2017 19:23
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

Successfully merging this pull request may close these issues.

4 participants