Currently SyntaxTree stores subtrees in a std::sync::Arc so that rayon traits can be used to iterate inside ContextSearch methods in parallel.
This forces the consumers of zia to use a multithreaded implementation with the overhead of Arc compared to std::rc::Rc.
It also makes it hard to assess whether multithreaded evaluation is beneficial for performance and by how much.
Arc is spread all across the codebase. Even though it's more of an implementation detail it would be hard to switch to Rc because of how many lines need to be changed
Solution
Promote SyntaxTree to a trait with an associated type SharedSyntax that can be implemented as Rc<Self> or Arc<Self> and an associated ConceptId that can match SnapShot's associated type.
Use macro_rules! to define a macro to implement SyntaxTree for multiple types of reference counted smart pointers without having to repeat yourself
A type parameter that impl SyntaxTree can be used to parameterise ContextSearch and Context to generalise over syntax tree types.
Define a trait that ContextSearch implements that has methods that iterate on a single thread for Rc syntax trees and multiple threads for Arc syntax trees.
Define convenient type aliases for Context with Arc and Rc so that consumers understand the difference.
Put use of rayon behind a feature gate so that consumers don't have to compile rayon if they only want a single threaded implementation
Repeat steps 1 and 2 for other recursively Arced data structures
Problem
Currently SyntaxTree stores subtrees in a
std::sync::Arc
so thatrayon
traits can be used to iterate insideContextSearch
methods in parallel.zia
to use a multithreaded implementation with the overhead ofArc
compared tostd::rc::Rc
.Arc
is spread all across the codebase. Even though it's more of an implementation detail it would be hard to switch toRc
because of how many lines need to be changedSolution
SyntaxTree
to a trait with an associated typeSharedSyntax
that can be implemented asRc<Self>
orArc<Self>
and an associatedConceptId
that can matchSnapShot
's associated type.macro_rules!
to define a macro to implementSyntaxTree
for multiple types of reference counted smart pointers without having to repeat yourselfimpl SyntaxTree
can be used to parameteriseContextSearch
andContext
to generalise over syntax tree types.ContextSearch
implements that has methods that iterate on a single thread forRc
syntax trees and multiple threads forArc
syntax trees.Context
withArc
andRc
so that consumers understand the difference.rayon
behind a feature gate so that consumers don't have to compilerayon
if they only want a single threaded implementationArc
ed data structures