Replies: 1 comment 4 replies
-
The way cascadestudio does caching is partially the reason I built replicad - it forces the system to be more integrated as a framework (instead of a library). That said, caching is very useful, not only for the case you mention, but also to make configuration changes faster. What about using javascript and the libraries that exist? I did a quick hack: const { makeBaseBox } = replicad;
import memoize from 'https://cdn.jsdelivr.net/npm/memoize@10.1.0/+esm'
function memo(fn, memoName) {
const name = memoName || fn.name
if (!("cacheMem" in globalThis)) {
globalThis.cacheMem = new Map()
}
let cache;
if (globalThis.cacheMem.has(fn.name)) {
cache = globalThis.cacheMem.get(name)
} else {
cache = new Map()
globalThis.cacheMem.set(name, cache)
}
return memoize(fn, {cache})
}
const newBox = memo(function newBox (width) {
console.log("new box")
return makeBaseBox(width, 50, 10)
})
export default function main() {
let base = newBox(50);
return base
} Note that you could get a bit more in depth (i.e. use the code as the function key, have a LRU cache, do some magic with the replicad objects). But this could all be packaged as a library to import instead of being part of the workbench. Obviously, this is not working without any input from the user - but it gives more detailed control (which tends to be useful when caching as invalidation is not always easy) Do you see another issue with this approach? |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Currently, when iterating on code in the workbench or when changing parameters, the kernel needs to redo the same operations over and over, so that changing one parameter, or a line of code at the end of a project requires a full rebuild. This can be very slow for some projects with complex geometry and/or text.
I think it could be helpful to maintain some kind of state or operation cache, so that expensive operations, like complex booleans, would not need to be performed again unless their inputs changed.
Cascadestudio handles this use case with this CacheOp method, which serializes the incoming parameters, stripping the pointer IDs from open cascade objects, and just stores the results in a cache object.
Beta Was this translation helpful? Give feedback.
All reactions