refactor: use Box to store large config objects and add memory usage tests

- Refactored config-related structs to use Box for storing large objects (e.g., IRuntime, IProfiles, PrfItem) to reduce stack memory usage and improve performance.
- Updated related methods and assignments to handle Boxed types correctly.
- Added and improved unit tests to compare memory usage between Boxed and non-Boxed config objects, demonstrating the memory efficiency of Box.
- Test output now shows the size difference between stack-allocated and heap-allocated (Box) config objects.
This commit is contained in:
Tunglies
2025-06-06 14:49:23 +08:00
parent 564fe15df2
commit 689042df60
6 changed files with 91 additions and 44 deletions

View File

@@ -104,10 +104,10 @@ fn test_script() {
let (config, results) = use_script(script.into(), config, "".to_string()).unwrap();
let _ = serde_yaml::to_string(&config).unwrap();
let origin_size = std::mem::size_of_val(&config);
dbg!(origin_size);
let box_size = std::mem::size_of_val(&Box::new(config));
dbg!(box_size);
let yaml_config_size = std::mem::size_of_val(&config);
dbg!(yaml_config_size);
let box_yaml_config_size = std::mem::size_of_val(&Box::new(config));
dbg!(box_yaml_config_size);
dbg!(results);
assert!(origin_size > box_size);
assert!(box_yaml_config_size < yaml_config_size);
}