Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: remove in-memory SerializedModuleCache #136

Merged
merged 10 commits into from
Jan 7, 2025

Conversation

mattyg
Copy link
Member

@mattyg mattyg commented Dec 24, 2024

Resolves holochain/holochain#3536

The diff is a hard to read but I think the code is more legible. Let me know if you think of more tests that would be good to add.

@@ -118,4 +168,56 @@ mod tests {
assert_eq!(*deserialized_cached_module, *module);
}
}

#[test]
fn cache_get_from_fs() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test that:

  • builds module, serializes, writes to filesystem at expected path
  • gets module from ModuleCache
  • asserts that module now exists in deserialized in-memory path

}

#[test]
fn cache_save_to_memory_only() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache a module to in-memory deserialized module cache only


#[test]
fn cache_test() {
fn cache_save_to_memory_and_fs() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cache a module to both filesystem and in-memory deserialized module caches

crates/host/src/module.rs Outdated Show resolved Hide resolved
@mattyg mattyg requested a review from a team December 24, 2024 20:13
};
self.put_item(key, Arc::new(serialized_module.clone()));
// Save serialized module to filesystem cache
self.add_to_filesystem_cache(key, serialized_module)?;
Copy link
Member Author

@mattyg mattyg Dec 24, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that we first save to filesystem, then add to in-memory cache. Thus if the process is interrupted after saving to the filesystem, it will still be added to the in-memory cache next time it is fetched.

But this made me realize -- if the process is interrupted while saving to the filesystem and the file is corrupted then it will error every time we try to deserialize it. I made an issue to address this: #137

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we should be removing the file from disk if we load it and can't use it?

Copy link
Member

@ThetaSinner ThetaSinner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking good. I like that in new code like the tests you've got just "in memory" and "file system" references. I'd go a little further and try to drop the serialized vs deserialized naming entirely. There is now one way to hold modules in memory and we have to serialize to save to storage. I think that's clear enough without having "deserialized" in the name. I see why it was there and that you've removed quite a few instances, I'm just thinking we can complete that cleanup.

Otherwise, the code is nice and clear :)

crates/host/src/module.rs Outdated Show resolved Hide resolved
crates/host/src/module.rs Outdated Show resolved Hide resolved
};
self.put_item(key, Arc::new(serialized_module.clone()));
// Save serialized module to filesystem cache
self.add_to_filesystem_cache(key, serialized_module)?;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds like we should be removing the file from disk if we load it and can't use it?

crates/host/src/module/wasmer_sys.rs Outdated Show resolved Hide resolved
deserialized_module_cache: Arc<RwLock<DeserializedModuleCache>>,

// A function to create a new compiler engine for every module
make_engine: fn() -> Engine,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having this in the cache is mixing concerns a little. I can't see the scope of this growing so I'm not too bothered. The caching and the production of working modules could be separated I think but if that's done later or never, then that's good with me :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense. I pulled out those fields and the calls that use them into a ModuleBuilder struct. Lmk what you think.

Copy link
Contributor

@jost-s jost-s left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

crates/host/src/module.rs Outdated Show resolved Hide resolved
@mattyg
Copy link
Member Author

mattyg commented Jan 7, 2025

I'd go a little further and try to drop the serialized vs deserialized naming entirely.

Good call, done. Let me know what you think.

@mattyg mattyg merged commit 4961063 into main Jan 7, 2025
15 checks passed
@mattyg mattyg deleted the feat/rm-serialized-module-cache branch January 7, 2025 20:16
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.

[Wasmer] Remove serialized module cache
3 participants