Open juntao opened 1 year ago
flows summarize
Hello, I am a serverless review bot on flows.network. Here are my reviews of code commits in this PR.
Summary of key changes:
.so
(AOT mode) or .wasm
files by checking their existence in the file system.Potential problems:
cc https://github.com/yomorun/yomo-wasmedge-tensorflow/pull/12
flows summarize
Hello, I am a serverless review bot on flows.network. Here are my reviews of code commits in this PR.
This patch includes changes to the WebAssembly (WASM) compilation and loading process for a Rust-based machine learning application. The key changes are as follows:
Corrections in README.md and README_CN.md:
rust_mobilenet_foods/src
to rust_mobilenet_food/src
.cargo build
.wasmedgec
.Changes in flow/app.go
:
initVM()
function to:
Potential Problems:
Although the changes in app.go
improve the way WASM files are found and loaded, they introduce coupling between the filename and the implementation. This could lead to issues if the filename changes in the future.
Handling both .wasm
and .so
files in the same build setup might create confusion for users who are not familiar with AOT compilation or shared objects. To avoid confusion, it may be beneficial to provide further information and clarification about the different options and their impact on performance in the README files.
cc https://github.com/yomorun/yomo-wasmedge-tensorflow/pull/12
Hello, I am a serverless review bot on flows.network. Here are my reviews of changed source code files in this PR.
flow/app.go
The code is generally well-written, but there are a few potential issues and improvements to consider:
Handler
function, the error returned byinitVM()
is handled, but the error returned bybg.Execute("infer", img)
is not. This should be handled appropriately, e.g., by returning an appropriate value (e.g.,0, nil
) and logging the error.Multiple VM initializations
Handler
function is initializing a new VM each time it's called. This can result in high memory usage and low performance, especially if the handler is called frequently. A better approach would be to initialize the VM once (e.g., in themain
function or as a package-level variable) and reuse it. Note that this may require ensuring proper thread-safety if the handler can be called concurrently.Use of
select {}
select {}
statement at the end of themain
function is used to block the main goroutine indefinitely. While this is a valid way to prevent the program from exiting, using signals would be a more idiomatic and elegant approach. You can catch the termination signal (e.g.,os.Interrupt
) and gracefully shut down the application.fmt.Sprintf
genSha1
function, thefmt.Sprintf
call can be replaced by a simple type conversion.sha1.New()
returns a hash.Hash, which means.Sum(nil)
returns a slice of bytes that can be cast directly to a hex-encoded string.Avoid global state (if possible)
counter
variable, can make it harder to reason about the program and test individual components. Consider injecting the necessary state into your components when initializing them, or encapsulating state within constructs like a struct with associated methods. However, using atomic counters is quite reasonable for this specific use case.Declare constants at the beginning of the file
Include documentation
These changes can help improve the code quality, but overall, the code is generally well-structured and easy to read.
The key change in the patch is related to loading the appropriate file for WasmEdge's VM. Instead of directly loading a hardcoded filename
rust_mobilenet_food_lib.wasm
, the patch introduces a loop that searches for the correct file with either a.so
or.wasm
extension.Here's the breakdown of the change:
A new variable
filename
is introduced and set to the initial part of the filename "rust_mobilenet_food_lib".A flag variable
ok
is set tofalse
initially.A loop iterates over a list of two possible suffixes: ".so" and ".wasm".
During the loop, the patch checks if the file exists with the current suffix:
filename
, theok
flag is set totrue
, and the loop is terminated usingbreak
.After the loop, if the
ok
flag is stillfalse
, this means none of the expected files were found, and an error is returned with a message indicating the problem.Finally, instead of loading the hardcoded file, the
vm.LoadWasmFile
method is called with thefilename
resulting from the loop. This allows the VM to load the correct file with either a.so
or.wasm
extension.cc https://github.com/yomorun/yomo-wasmedge-tensorflow/pull/12