fuchsia / third_party / github.com / google / starlark-go / refs/heads/upstream/profile-optimize-fibonacci^! / .

commit | 17a6e6d39f446f70cc2c7a209a5ce30d957778ec | [log] [tgz] |
---|---|---|

author | Alan Donovan <adonovan@google.com> | Sat Jan 21 22:36:37 2023 -0500 |

committer | Alan Donovan <adonovan@google.com> | Sat Jan 21 23:04:08 2023 -0500 |

tree | 756ebe4189320de3012168f1d67a431032589e79 | |

parent | 42872f4d8faac131980be5f3bc9505851d863fff [diff] |

starlark: optimize TestProfile Previously, the test would compute the first 100,000 elements of the Fibonacci sequence, holding them all in an array. Since elements may have over 20,000 digits, this allocates a lot of memory, which, under tight ulimits of virtual address space, in conjunction with the mmap int optimization, may cause the process to have insufficient virtual address space to allocate the necessary memory. This change causes it to compute but not retain the elements of the sequence. Fixes google/starlark-go#455

diff --git a/starlark/profile_test.go b/starlark/profile_test.go index 2781833..515d7d4 100644 --- a/starlark/profile_test.go +++ b/starlark/profile_test.go

@@ -31,10 +31,10 @@ const src = ` def fibonacci(n): - res = list(range(n)) - for i in res[2:]: - res[i] = res[i-2] + res[i-1] - return res + x, y = 1, 1 + for i in range(n): + x, y = y, x+y + return y fibonacci(100000) `