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
docs: clarify section on coroutine memory consumption #3225
Conversation
Updates the section "Coroutines are light-weight" to clarify its comparison of the resource-intensiveness of coroutines and threads. The content is much the same, I've attempted to make it follow the pattern of the other sections by introducing the conceptual point first, then presenting the code sample. This commit also makes the code sample in this section runnable and omits the surrounding runBlocking block.
docs/topics/coroutines-basics.md
Outdated
JVM's available memory when using threads can be expressed using coroutines | ||
without hitting resource limits. For example, the following code launches | ||
100000 distinct coroutines that each wait 5 seconds and then print a period | ||
('.'): |
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.
('.'): | |
('.'), all the while consuming very little memory: |
Or something in this vein. Otherwise, the whole point is obscured.
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.
Good point! Added.
docs/topics/coroutines-basics.md
Outdated
``` | ||
{kotlin-runnable="true" kotlin-min-compiler-version="1.3"} |
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.
This would go against our narrative :)
Try running https://play.kotlinlang.org/#eyJ2ZXJzaW9uIjoiMS42LjEwIiwiY29kZSI6ImltcG9ydCBrb3RsaW54LmNvcm91dGluZXMuKlxuLy9zYW1wbGVTdGFydFxuZnVuIG1haW4oKSA9IHJ1bkJsb2NraW5nIHtcbi8vc2FtcGxlU3RhcnRcbiAgICByZXBlYXQoMTAwXzAwMCkgeyAvLyBsYXVuY2ggYSBsb3Qgb2YgY29yb3V0aW5lc1xuICAgICAgICBsYXVuY2gge1xuICAgICAgICAgICAgZGVsYXkoNTAwMEwpXG4gICAgICAgICAgICBwcmludChcIi5cIilcbiAgICAgICAgfVxuICAgIH1cbn1cbi8vc2FtcGxlRW5kIiwicGxhdGZvcm0iOiJqYXZhIiwiYXJncyI6IiJ9
However lightweight coroutines are, they still take some memory, more that our playground allocates.
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.
ah, I figured something like this might be the case--I added a comment noting as much so that future contributors don't make the same mistake, I felt there was probably a good reason for this one not being runnable but didn't see any immediate indication as to why, thus the PR--thanks for letting me know!
//sampleEnd | ||
} |
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.
Given that the code is not runnable, I think a better choice would be to remove //sampleStart
and //sampleEnd
, given how they aren't recognized for code that is not runnable: https://kotlinlang.org/docs/coroutines-basics.html#coroutines-are-light-weight
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.
Done, thanks!
- Add some additional text that emphasizes that the example code has a small memory footprint. - Add a note that we should not make the example runnable (since it will exhaust the playground heap) - Remove //sample(Start|End) comments since they are not recognized for code that is not runnable.
Thanks! |
Updates the section "Coroutines are light-weight" to clarify its comparison of the resource-intensiveness of coroutines and threads. The content is much the same. This commit also makes the code sample in this section runnable and omits the surrounding runBlocking block.
Updates the section "Coroutines are light-weight" to clarify its
comparison of the resource-intensiveness of coroutines and threads. The
content is much the same, I've attempted to make it follow the pattern
of the other sections by introducing the conceptual point first, then
presenting the code sample.
This commit also makes the code sample in this section runnable and
omits the surrounding runBlocking block.