Conversation
- Get rid of unnecessary call to Free (reduces overall latency) Fixes knqyf263#78 Signed-off-by: Alex In <reexistent@gmail.com>
|
Interesting, how can we reproduce memory leak so observe it? |
|
@LukaGiorgadze please see original issue, I provided steps to reproduce. |
|
I've been working on using AssemblyScript Wasm compiler. This I have working with go-plugins, however is far more sensitive to memory leaks. I agree these two changes reduce memory leakage. This is another issue that is causing memory leaks. The main cause of memory leaks is Line 34 in c156889 This This effectively gives memory allocation a TTL. A call to
Clearly the second change is more significant. I have not done enough use scenarios to generate a PR yet. This comment is really support for this PR. My testing and usage shows it is good. There is more to do to reduce memory leaks (allocations that are not returned). I will raise at least 1 more PR when I have run more usage scenarios. |
knqyf263
left a comment
There was a problem hiding this comment.
Thanks. I haven’t had time to test it, but the changes look fine.
|
@knqyf263 Approximately in 1 month I'll become active contributor of this project, I'm using it for my open-source project. Thanks for keeping it live. |
Issue #, if available:
#78
Description of changes:
The reason for the issue is that GC not run due to cooperative nature of Go runtime in Wasm.
This is fixed by explicitly yielding control with
runtime.Gosched. Another option is to force run of GC. It also works, however performance is worse, apparently because it's not necessary to have whole GC cycle on every call toFree. It's enough to make sure that it will run eventually.I also removed unnecessary call to
Freeon memory managed by Wasm module itself. This is not needed in any case:Freewill either be no-op or lead to further difficult-to-debug memory problemsLast point also reduces overall latency by few microseconds which could have been counted in highly loaded systems.
@knqyf263 I didn't add benchmark tests which I used when reproducing #78, but if you think they make any sense, I can add
BenchmarkGreetMorningandBenchmarkGreetEveningsimilar to the code in the above issue. Not sure if it's ok to run them during test phase in CI/CD. It will need a couple of minutes to complete and should fail because of OOM if original issue not fixed.By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.