-
Notifications
You must be signed in to change notification settings - Fork 328
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
Benchmark lazy infinite sieve of Eratosthenes #11351
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
530ad01
Benchmark lazy infinite list to compute 10000 prime numbers
JaroslavTulach 563f116
Include insight-heap-tool
JaroslavTulach 2afcfa5
Documenting use of --heap.dump option in Enso program
JaroslavTulach a1517ed
scalafmtSbt
JaroslavTulach 33607c2
Start the group name with Sieve_ to sort next to the other Sieve benc…
JaroslavTulach File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from Standard.Base import all | ||
|
||
type Stream | ||
private Item head:Integer ~tail:Stream | ||
|
||
primes -> Stream = | ||
is_prime s:Stream n:Integer = | ||
if n%s.head == 0 then False else | ||
if s.head*s.head > n then True else | ||
@Tail_Call is_prime s.tail n | ||
|
||
find_next primes:Stream n:Integer = | ||
n_is_prime = is_prime primes n | ||
|
||
if n_is_prime then Stream.Item n (find_next primes n+1) else | ||
@Tail_Call find_next primes n+1 | ||
|
||
|
||
p = Stream.Item 2 (find_next p 3) | ||
p | ||
|
||
|
||
compute_nth_prime n -> Integer = | ||
take_nth s:Stream n:Integer -> Integer = | ||
if n <= 1 then s.head else | ||
@Tail_Call take_nth s.tail n-1 | ||
|
||
take_nth primes n | ||
|
||
|
||
|
||
main n=Nothing = | ||
print_nth s:Stream n:Integer|Nothing -> Nothing = | ||
if n.is_nothing.not && n <= 0 then IO.println "" else | ||
IO.print s.head | ||
IO.print " " | ||
@Tail_Call print_nth s.tail (n.if_not_nothing n-1) | ||
|
||
compute_and_print_nth nth:Integer|Nothing = | ||
p = primes | ||
print_nth p nth | ||
|
||
compute_and_print_nth n | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// | ||
// Demo script showing a "serialization" of an Enso atom structure | ||
// to a `.hprof` file which can be opened and analyzed in VisualVM | ||
// | ||
// Based on following tutorial: | ||
// https://www.graalvm.org/jdk21/tools/graalvm-insight/manual/#heap-dumping | ||
// | ||
// Execute from `sbt` as: | ||
// ``` | ||
// sbt:enso> runEngineDistribution \ | ||
// --vm.D=polyglot.heap.dump=/tmp/sieve.hprof \ | ||
// --vm.D=polyglot.insight=Benchmarks/src/Sieve/heap_dump_lazy_sieve.js \ | ||
// --run test/Benchmarks/src/Sieve/Lazy_Sieve.enso | ||
// 10000 | ||
// ``` | ||
// | ||
// This GraalVM script waits for the end execution of `compute_and_print_nth` function | ||
// to store value of its `p` local variable (containing linked list of prime numbers) | ||
// into `/tmp/sieve.hprof` - a GraalVM serialization for Truffle languages! | ||
|
||
insight.on( | ||
'return', | ||
(ctx, frame) => { | ||
for (let p in frame) { | ||
print(`found ${p} with ${frame[p]} value`) | ||
} | ||
let value = frame.p | ||
heap.dump({ | ||
format: '1.0', | ||
depth: 5000, | ||
events: [ | ||
{ | ||
stack: [ | ||
{ | ||
at: ctx, | ||
frame: { | ||
primes: value, | ||
}, | ||
}, | ||
], | ||
}, | ||
], | ||
}) | ||
print('Heap dump generated!') | ||
}, | ||
{ | ||
roots: true, | ||
rootNameFilter: '.*compute_and_print_nth', | ||
}, | ||
) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To generate this heap dump execute:
sbt:enso> runEngineDistribution --vm.D=polyglot.heap.dump=/tmp/sieve.hprof --vm.D=polyglot.insight=Benchmarks/src/Sieve/heap_dump_lazy_sieve.js --run test/Benchmarks/src/Sieve/Lazy_Sieve.enso 10000
This is how the heap dump looks like in VisualVM: