-
Notifications
You must be signed in to change notification settings - Fork 36
Appendix on memory usage #1302
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
Appendix on memory usage #1302
Conversation
|
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.
Left some suggestions.
documentation/public/user-guide/09-appendix/02-slang-memory-management/index.md
Outdated
Show resolved
Hide resolved
documentation/public/user-guide/09-appendix/02-slang-memory-management/index.md
Outdated
Show resolved
Hide resolved
documentation/public/user-guide/09-appendix/02-slang-memory-management/index.md
Outdated
Show resolved
Hide resolved
documentation/public/user-guide/09-appendix/02-slang-memory-management/index.md
Outdated
Show resolved
Hide resolved
documentation/public/user-guide/09-appendix/02-slang-memory-management/index.md
Outdated
Show resolved
Hide resolved
documentation/public/user-guide/09-appendix/02-slang-memory-management/index.md
Outdated
Show resolved
Hide resolved
documentation/public/user-guide/09-appendix/02-slang-memory-management/index.md
Outdated
Show resolved
Hide resolved
documentation/public/user-guide/09-appendix/02-slang-memory-management/index.md
Outdated
Show resolved
Hide resolved
documentation/public/user-guide/09-appendix/02-slang-memory-management/index.md
Outdated
Show resolved
Hide resolved
Co-authored-by: Gustavo Giráldez <[email protected]>
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.
I like this guide. It's clear, and the suggestion isn't resorting to manual memory management.
@@ -0,0 +1,39 @@ | |||
# 9.2. Considerations on memory usage |
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.
I think there is a difference between the title Considerations on memory usage
and the slug slang-memory-management
. I suggest consolidating it here + index.md
+ NAVIGATION.md
above:
# 9.2. Considerations on memory usage | |
# 9.2. Slang Memory Management |
|
||
## Internal vs external memory | ||
|
||
JavaScript engines distinguish between the memory space that contains JavaScript objects, called _internal memory_ or _heap space_, and the space used for Wasm components, called _external memory_. The Slang objects that you interact with reside in internal memory. However, a Slang object, such as a `Cursor`, holds a _handle_ to a Wasm component that manages a corresponding resource in the Rust implementation. In the case of a `Cursor`, that resource contains among other things _a reference to the entire parsing tree_. Therefore, an instance of the `Cursor` class in JavaScript is lightweight in terms of internal memory as it only contains the handle number. But it is associated with a significant amount of external memory—the actual cursor in Wasm-land. |
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.
JavaScript engines distinguish between the memory space that contains JavaScript objects, called _internal memory_ or _heap space_, and the space used for Wasm components, called _external memory_. The Slang objects that you interact with reside in internal memory. However, a Slang object, such as a `Cursor`, holds a _handle_ to a Wasm component that manages a corresponding resource in the Rust implementation. In the case of a `Cursor`, that resource contains among other things _a reference to the entire parsing tree_. Therefore, an instance of the `Cursor` class in JavaScript is lightweight in terms of internal memory as it only contains the handle number. But it is associated with a significant amount of external memory—the actual cursor in Wasm-land. | |
JavaScript engines distinguish between the memory space that contains JavaScript objects, called _internal memory_ or _heap space_, and the space used for Wasm components, called _external memory_. The Slang objects that you interact with reside in internal memory. However, a Slang object, such as a `Cursor`, holds a _handle_ to a Wasm component that manages a corresponding resource in the Rust implementation. In the case of a `Cursor`, that resource contains among other things _a reference to the entire parsing tree_. Therefore, an instance of the `Cursor` class in JavaScript is lightweight in terms of internal memory as it only contains the handle number. But it is associated with a significant amount of external memory—the actual cursor+tree in Wasm-land. |
|
||
In our tests, adding this timeout was sufficient to give the `FinalizationRegistry` time to properly clean up the objects. The external memory usage grows at the start, but eventually stabilizes and remains steady. | ||
|
||
In an interactive environment, such as a browser, it should not be necessary to add such a pause, as the engine has several opportunities to perform cleanup while waiting for user input. |
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.
In an interactive environment, such as a browser, it should not be necessary to add such a pause, as the engine has several opportunities to perform cleanup while waiting for user input. | |
In an interactive environment, such as an IDE or a browser, it should not be necessary to add such a pause, as the engine has several opportunities to perform cleanup while waiting for user input. |
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.
Love this. Left a couple of suggestions.
No description provided.