Functions: make multi functions smaller and cheaper to construct in many cases
Previously, the signature of a `MultiFunction` was always embedded into the function. There are two issues with that. First, `MFSignature` is relatively large, because it contains multiple strings and vectors. Secondly, constructing it can add overhead that should not be necessary, because often the same signature can be reused. The solution is to only keep a pointer to a signature in `MultiFunction` that is set during construction. Child classes are responsible for making sure that the signature lives long enough. In most cases, the signature is either embedded into the child class or it is allocated statically (and is only created once).
This commit is contained in:
@@ -115,7 +115,7 @@ MFNetworkEvaluator::MFNetworkEvaluator(Vector<const MFOutputSocket *> inputs,
|
||||
: inputs_(std::move(inputs)), outputs_(std::move(outputs))
|
||||
{
|
||||
BLI_assert(outputs_.size() > 0);
|
||||
MFSignatureBuilder signature = this->get_builder("Function Tree");
|
||||
MFSignatureBuilder signature{"Function Tree"};
|
||||
|
||||
for (const MFOutputSocket *socket : inputs_) {
|
||||
BLI_assert(socket->node().is_dummy());
|
||||
@@ -144,6 +144,9 @@ MFNetworkEvaluator::MFNetworkEvaluator(Vector<const MFOutputSocket *> inputs,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
signature_ = signature.build();
|
||||
this->set_signature(&signature_);
|
||||
}
|
||||
|
||||
void MFNetworkEvaluator::call(IndexMask mask, MFParams params, MFContext context) const
|
||||
|
||||
Reference in New Issue
Block a user