Skip to content

Conversation

@apepkuss
Copy link
Collaborator

@apepkuss apepkuss commented Apr 1, 2023

In this PR, the host function design is improved to support removing host functions from the lazy static HOST_FUNCS.

@apepkuss apepkuss requested a review from hydai as a code owner April 1, 2023 18:06
@apepkuss apepkuss force-pushed the rust/refactor-function branch from d62f68b to 93bc460 Compare April 1, 2023 18:07
@apepkuss
Copy link
Collaborator Author

apepkuss commented Apr 2, 2023

@hydai Could you please help review this PR? Thanks a lot!

Copy link
Contributor

Hello, I am a serverless review bot on flows.network. Here are my reviews of code commits in this PR.


Based on the set of reviews provided, I see that there are several patches that aim to improve code efficiency, test reliability, and workflow stability. The changes themselves look straightforward, simple, and well-documented, with some potential problems or limitations specified. The reviewers also raised some concerns about the commit message's clarity and the lack of information about the codebase's context. Overall, the patches seem reasonable and unlikely to cause major issues, but more testing and validation may be necessary for some changes.

Details

Commit 1

The patch removes some code that appears to be no longer needed from the wasmedge-sys Rust crate. The change also includes a new unit test that creates a large number of new host functions, which could potentially cause performance problems or hit resource limits on the system. However, the test could be useful for testing the code's ability to handle large numbers of host functions effectively. Overall, the changes themselves look straightforward and simple.

One thing it's worth noting is that the commit message could be more informative, as the subject line "refactor(rust-sys): remove the inappropriate code" is somewhat vague and does not provide substantial detail.

Commit 2

This patch adds support for removing real function in Rust-Sys of Wasmedge. The key changes include:

  • Create a footprint for each host function in Function::from_raw_fn_ptr().
  • Remove the real function from HOST_FUNCS in Function::drop().
  • Create a HOST_FUNC_FOOTPRINTS hash map to store the mapping between the address of each host function pointer to the key of HOST_FUNCS.

This patch looks reasonable and well-documented to me. However, there is a potential problem in a loop of unit testing (lines 518-556). The declaration of start_num before the loop does not reflect the initial length of HOST_FUNCS, which is a problem for the assertion on line 559. Instead, the test should store the initial length of HOST_FUNCS before the loop starts to compare it to the total number of functions added to HOST_FUNCS at the end of the loop.

Commit 3

This patch is a minor change to the test code for bindings/rust/wasmedge-sys/src/instance/function.rs. The key change is replacing a specific assertion that checks for an exact match of the length of funcs with a conditional assertion that checks if funcs is smaller or equal to the length of HOST_FUNCS.

There don't seem to be any potential problems with this patch as it appears to be a fairly simple change which updates the existing test code to be more robust. However, it may be helpful to know more about the context before accepting this patch.

Commit 4

This patch updates the GitHub Actions workflow for the Rust bindings in a specific GitHub repository. Specifically, it modifies the cargo test commands by adding the flag --test-threads=1 to set the number of test threads to 1. The purpose of this change is to prevent unexpected test failures due to race conditions when multiple tests are running concurrently.

One potential problem that I see is that setting the number of test threads to 1 may slow down the test execution, especially if there are a large number of tests. This may increase the overall build and test time, which could reduce the efficiency of the workflow.

Overall, this patch seems like a reasonable change to improve the reliability of the tests in the Rust bindings.

Commit 5

This patch is updating test code for a function in the rust-sys bindings of the Wasmedge project. Specifically, it's changing an assertion from a comparison to an equality check. It also includes a commit message and signed-off-by tag.

One potential issue that stands out is that the commit message doesn't explain why the change is being made or what problem it is resolving. Additionally, without more context about the codebase itself and the purpose of this test function, it's difficult to confidently assess whether this change will have any unforeseen effects.

Commit 6

This patch updates the GitHub Actions workflow for a Rust static library project to test with newer versions of Rust (1.66, 1.67, 1.68) and runs the tests using a single thread (--test-threads=1). The change exports environment variables for the Wasmedge directory and builds directory. These changes are expected to improve the stability and performance of the project.

There are no potential problems in this patch.

Commit 7

This patch updates the test code in the function.rs file by changing the loop limit from 10 to 1,000,000. It seems to be a performance optimization for testing purposes.

Potential problems could arise if this change impacts the memory or resource usage of the code. It's also possible that this change could cause the test to run much longer, so testing the test suite before and after the change may be necessary to validate the effect of this patch.

hydai
hydai previously approved these changes Apr 2, 2023
@apepkuss
Copy link
Collaborator Author

apepkuss commented Apr 2, 2023

@hydai I added the option --test-threads=1 for Fedora in the bindings-rust workflow. Sorry, I forgot it in the previous commits. Please help review it again. Thanks a lot!

@apepkuss apepkuss merged commit dad018a into WasmEdge:master Apr 2, 2023
@apepkuss
Copy link
Collaborator Author

apepkuss commented Apr 2, 2023

@hydai Thanks for the review!

@apepkuss apepkuss deleted the rust/refactor-function branch April 2, 2023 10:19
@juntao
Copy link
Member

juntao commented Apr 3, 2023

flows summarize again

Copy link
Contributor

Hello, I am a serverless review bot on flows.network. Here are my reviews of code commits in this PR.


The reviews include patches with various updates and modifications to Rust libraries and workflows. The changes include adding new unit tests, modifying test assertions, updating CI workflows with flags and environment variables, and updating Rust versions. Overall, the patches seem reasonable and do not show any potential problems. However, reviewers recommend further testing to gauge the impact on performance, especially for large iteration counts.

Details

Commit 1

This patch makes some changes to the function.rs file of wasmedge-sys. The changes include removing some inappropriate code and adding a new unit test test_crazy_function_creation().

Overall, the changes seem to be reasonable, and the new test is helpful to ensure that the system handles the creation of a large number of host functions well. However, reviewers might want to examine the test function more thoroughly. It creates one million host functions, which may be too large and slow down the system. It may be more appropriate to reduce this value to a smaller number or to use a test case using a randomly generated number of hosts.

Commit 2

This pull request adds support for removing a real function, and also introduces a HashMap to store a mapping between the address of each host function pointer, and the key of the HOST_FUNCS HashMap. Potential issues to consider include:

  • There are no test cases included for the new removal feature. Tests should be inclusive of any new changes.
  • There could potential performance issues with the HOST_FUNC_FOOTPRINTS HashMap. Further testing may be required to gauge the impact on performance.

Commit 3

This patch updates the test code for the Rust sys bindings in the function.rs file. Specifically, it modifies an assertion to check that the number of host functions registered in a struct is greater than or equal to the number of functions requested to be registered. As a reviewer, I don't see any potential problems in this change.

Commit 4

This patch updates the bindings-rust GitHub workflows for testing and building the project to include the --test-threads=1 flag to ensure thread safety. It also includes various environment variable exports to point to the correct directories. No potential problems were identified in this patch.

Commit 5

This is a patch that updates the test code for a Rust library. Specifically, it modifies the function tests() in the function.rs file. The change updates the assertion so that assert_eq! is used instead of assert!. This is the only change in the patch, which inserts three lines of code and removes two lines of code in function.rs.

There are no identified potential problems in this patch. The change appears to be straightforward and should not cause any issues.

Commit 6

This patch updates the CI workflow for building a Rust static library. The patch specifically updates the Rust version to 1.66, 1.67, and 1.68, and adds the --test-threads=1 flag to the cargo test command.

There do not appear to be any potential problems with this patch. However, it is always a good idea to double-check that the new Rust versions are supported by the project's dependencies and that the test results remain consistent.

Commit 7

This is a small fix that updates the function.rs file under the src/instance folder to modify the test code. Specifically, it is changing the number of iterations in a loop from 10 to 1,000,000. The purpose of this change is not clearly stated in the commit message. However, it looks like the author is testing performance improvements.

There seem to be no potential problems with this change. However, it would be good to verify that the increased number of iterations does not cause any significant issues with the test.

Commit 8

This patch updates the CI workflow for Rust bindings, specifically the cargo test command. It adds the --test-threads=1 option to limit the number of threads used for testing. This is likely done to reduce resource utilization.

There do not appear to be any potential problems with this patch.

@WasmEdge WasmEdge deleted a comment from alabulei1 Apr 5, 2023
@juntao
Copy link
Member

juntao commented Apr 5, 2023

flows summarize with GPT4

Copy link
Contributor

Hello, I am a serverless review bot on flows.network. Here are my reviews of code commits in this PR.


Overall Summary:

This set of patches involves modifications primarily to the Rust bindings for the wasmedge-sys component, the related CI workflow, and the test files. The primary focus of these changes is to improve memory management, remove limits on the number of host functions, and update assertions in tests.

Potential issues and errors:

  1. Removing the check for host function capacity and the 'MAX_HOST_FUNC_LENGTH' environment variable could lead to excessive resource consumption, affecting system stability and performance.
  2. The test_crazy_function_creation function may consume a significant amount of system resources and take a long time to finish. Additionally, increasing the loop count from 10 to 1,000,000 in function.rs might lead to performance concerns and resource exhaustion.
  3. Changing the assertions in tests to use assert! instead of assert_eq! (and vice versa) could lead to altered test outcomes and potential false test failures.
  4. Mutexes and RwLocks in the code can potentially cause deadlocks if not implemented carefully.
  5. Updating the Rust CI workflow to restrict the number of test threads to 1 across all platforms could slow down the CI process.

Important Findings:

  1. Memory management has been improved through the addition of support for removing real functions in Rust, and the creation of a footprint for host functions.
  2. Changes have been made to the Rust bindings CI workflow, including updating the operating systems matrix and Rust compiler versions matrix, as well as modifying the cargo test commands to set the test-threads to 1.
  3. The various changes to the test files involve updating assertions and modifying test scenarios, affecting the conditions that are being checked and the performance of the tests.

Given these changes, it's important to ensure that potential issues such as deadlocks, resource exhaustion, and false test failures are mitigated. Also, be cautious when removing limitations on host functions, as it could impact overall system stability and performance.

Details

Commit 1

This patch has made changes to the following file:

  • bindings/rust/wasmedge-sys/src/instance/function.rs

Key changes:

  1. Removal of the code block that checks if the number of host functions has reached its capacity. It returns an error if the condition is met.
  2. Addition of test_crazy_function_creation function to test the function creation process for 1,000,000 times.

Potential problems:

  1. Removing the capacity check may lead to a situation where too many host functions are created, consuming system resources.
  2. The test test_crazy_function_creation could use system resources excessively and it may take a long time to finish.

Commit 2

Summary of changes in GitHub Patch:

  1. Added support for removing real function in Rust.
  2. Created a footprint for the host function and used it for better memory management.
  3. Updated the test to check added functionality and print some debug information.
  4. Removed the environment variable 'MAX_HOST_FUNC_LENGTH' and made some changes in the HOST_FUNCS and HOST_FUNC_FOOTPRINTS.

Potential Problems:

  1. Removing the 'MAX_HOST_FUNC_LENGTH' environment variable might have some side effects if it was used in other parts of the code that were not updated.
  2. The Mutexes and RwLocks being used can cause potential deadlocks if not implemented carefully.
  3. The environment variable was meant to put limits on HashMaps, potentially the removal could lead to unbounded growth.

Overall, the changes look reasonable and improve memory management by adding support for removing real functions. However, be cautious about potential deadlocks and make sure any usage of removed environment variables is accounted for.

Commit 3

This patch modifies a Rust test file named function.rs under the wasmedge-sys directory.

Key changes:

  1. In the test module, the assert_eq!() macro is replaced with an assert!() macro.
  2. The updated assertion checks that the difference between the initial number of host functions (start_num) and the final number of host functions is greater than or equal to the number of functions.

Potential problems:

  1. If the intention was to check for an exact match in the number of new host functions, then using assert_eq!() would be more appropriate.
  2. It might be helpful to add a comment explaining why the change from the assert_eq!() macro to the assert!() macro was made, since the context is not clear from the patch alone.

Commit 4

The key changes in this patch are related to the Rust bindings Continuous Integration (CI) workflow. The file .github/workflows/bindings-rust.yml has been modified. The patch affects the testing steps of MacOS, Windows, and Fedora builds by adding the --test-threads=1 option.

Summary of changes:

  1. In the MacOS build job, cargo test and cargo test --examples have been updated with --test-threads=1 flag.
  2. Similarly, in the Windows build job, cargo test and cargo test --examples have been updated by adding --test-threads=1 flag.
  3. Lastly, in the Fedora build job, cargo test --workspace and cargo test --examples have been modified to include the --test-threads=1 flag.

The potential problems that can arise from these changes:

  • The --test-threads=1 flag will make the tests run sequentially, which could significantly slow down the CI process. Make sure this trade-off in testing speed is acceptable.

Commit 5

Summary of Key Changes:

  1. In the bindings/rust/wasmedge-sys/src/instance/function.rs file, the assert! macro used in the test module has been replaced with the assert_eq! macro.
  2. The old assert! checked if HOST_FUNCS.read().len() - start_num is greater than or equal to funcs.len(). The new assert_eq! checks for equality between HOST_FUNCS.read().len() - start_num and funcs.len().

Potential Problems:

  1. The change in the assertion condition might cause the test to fail in some scenarios where it previously passed. If the original logic was correct, and the >= condition was required, this change might lead to false test failures.
  2. If there are any other dependencies or other parts of the code that rely on the previous behavior, it could lead to issues in those areas as well.

Commit 6

Summary:

This patch updates the Rust CI workflow for building a static library.

Key changes:

  1. Updated the operating systems matrix: ubuntu-20.04, ubuntu-22.04
  2. Updated the Rust compiler versions matrix: 1.66, 1.67, 1.68
  3. Modified the cargo test commands to set the test-threads to 1.

Potential problems:

  • If any of the updated Rust compiler versions introduces breaking changes, it might cause issues with the project's dependencies and the codebase. Testing on multiple versions of Rust is important, but it is necessary to keep an eye on compatibility issues.
  • Setting the test-threads to 1 might cause the tests to run slower, as it is not leveraging the available parallelism. It might be suitable if tests are interfering with each other, but if there is no such reason, running tests with the default test-threads might be faster.

Commit 7

Summary of Key Changes:

  • In the bindings/rust/wasmedge-sys/src/instance/function.rs file, the loop counter for creating instance of FuncType has been changed from a range of 1 to 10 to 1 to 1,000,000.

Potential Problems:

  1. Performance Concern: Increasing the loop count from 10 to 1,000,000 may significantly increase the test execution time, especially if the creation of FuncType instances is expensive (memory or computation-wise).
  2. Resource Exhaustion: Creating 1,000,000 FuncType instances may cause a large memory allocation, which could lead to problems if the system has limited resources. Consider checking for any memory constraints and assess whether it's necessary to create such a large number of instances.

Commit 8

Summary of Key Changes:

  1. Modified .github/workflows/bindings-rust.yml to restrict the number of test threads to 1 when running cargo test and cargo test --examples commands for the Rust bindings.

Potential problems:

  1. The --test-threads=1 option potentially slows down the test execution time as it forces cargo test to run in a single-threaded mode rather than using multiple threads.

@WasmEdge WasmEdge deleted a comment from alabulei1 Apr 5, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants