# milestone_2 report
:::info
Latest Updated: Jan. 31st, 2024
:::
[TOC]
> This page illustrate what we have done in milestone 2 for mopro issue #21.
In this milestone, we will focus on swift tests in `mopro-ffi`, where rust code would be called in swift functions and we will test the utility and efficiency of `msm-benchmark` method.
## Main modifications
default feature in `mopro-ffi/Cargo.toml` is changed to `default=["gpu-benchmarks"]`. Thus, we don't have to use `--features` flag to enable `gpu-benchmarks` here.
### 1. Added Swift test in `mopro-ffi`
> path: `mopro-ffi/tests/bindings/test_mopro_gpu_benchmarks.swift`
<u>**reproducing steps (from root directory):**</u>
1. `cd ./mopro-ffi`
2. `RUSTFLAGS="-C opt-level=3" cargo test --test test_generated_bindings --release`
3. result:

### 2. Added GPU Benchmark Report in `mopro-ffi`
> path: `mopro-ffi/tests/bindings/test_mopro_gen_benchmarks_report.swift`
<u>**reproducing steps (from root directory):**</u>
1. `cd ./mopro-ffi`
2. `RUSTFLAGS="-C opt-level=3" cargo test --test test_generated_bindings --release`
3. The report will be generated at `mopro-core/benchmarks/gpu_explorations/msm_bench_swift_laptop.csv`
4. result:

The benchmarks result running in swift (technically not directly running on swift) and rust comparison is showing above.
We found that running `cargo test --test test_generated_bindings --release` do not run the test in **release mode**, and thus use `RUSTFLAG="-C opt-level=3"`
> The raw data is stored in this [sheet](https://docs.google.com/spreadsheets/d/1cl96S-Cdh6YRIbwofVp_nyDngzsNXNhCy0X_yvhtcuw/edit#gid=0)
- Average time for single MSM: $\approx{}$ 0.41 ms
- time for 10_000 MSM: $\approx{}$ 3_600 ms
- Approximately 1.24x slower than running directly on rust
## TODO Lists
- [X] mopro-ffi testing
> path: `mopro-ffi/tests/bindings`
- [X] Remove memory banchmarks (figuring out how to execute memory assessment)
- [X] Swift tests on laptop
- [X] performance of msm running time on laptop (in swift)
## Issues (just for log)
> memory assessment is surely not important right now, so we would focus on time improvement in the future work. (This part is just for recording the issue as a reference if we want to add memory estimate in the future.)
Main description is in [mopro/pr#56](https://github.com/oskarth/mopro/pull/56).
- Current `jemalloc` does not have ios-sim. However, in both x86_64-apple-ios and aarch64-apple-ios, it can be successfully compiled.
- The tests in `mopro-ffi/tests/bindings` only take the default features in `mopro-ffi/Cargo.toml`
Possible Solutions
1. Nested features
- gpu_benchmarks (with timing enabled)
- enable_memory
2. Try to benchmark memory usage using `std::alloc`
3. Try to functionalities of `jemalloc` directly on iOS device
## References
- [Integrate Rust in IOS](https://krirogn.dev/blog/integrate-rust-in-ios)
- [uniffi-bindgen version && Xcode issue](https://github.com/mozilla/uniffi-rs/issues/1922)
- [Chart](https://docs.google.com/spreadsheets/d/1cl96S-Cdh6YRIbwofVp_nyDngzsNXNhCy0X_yvhtcuw/edit#gid=0)