Functions: use static names for multi-functions
Previously, the function names were stored in `std::string` and were often created dynamically (especially when the function just output a constant). This resulted in a lot of overhead. Now the function name is just a `const char *` that should be statically allocated. This is good enough for the majority of cases. If a multi-function needs a more dynamic name, it can override the `MultiFunction::debug_name` method. In my test file with >400,000 simple math nodes, the execution time improves from 3s to 1s.
This commit is contained in:
@@ -43,7 +43,7 @@ template<typename In1, typename Out1> class CustomMF_SI_SO : public MultiFunctio
|
||||
MFSignature signature_;
|
||||
|
||||
public:
|
||||
CustomMF_SI_SO(StringRef name, FunctionT function) : function_(std::move(function))
|
||||
CustomMF_SI_SO(const char *name, FunctionT function) : function_(std::move(function))
|
||||
{
|
||||
MFSignatureBuilder signature{name};
|
||||
signature.single_input<In1>("In1");
|
||||
@@ -53,7 +53,7 @@ template<typename In1, typename Out1> class CustomMF_SI_SO : public MultiFunctio
|
||||
}
|
||||
|
||||
template<typename ElementFuncT>
|
||||
CustomMF_SI_SO(StringRef name, ElementFuncT element_fn)
|
||||
CustomMF_SI_SO(const char *name, ElementFuncT element_fn)
|
||||
: CustomMF_SI_SO(name, CustomMF_SI_SO::create_function(element_fn))
|
||||
{
|
||||
}
|
||||
@@ -92,7 +92,7 @@ class CustomMF_SI_SI_SO : public MultiFunction {
|
||||
MFSignature signature_;
|
||||
|
||||
public:
|
||||
CustomMF_SI_SI_SO(StringRef name, FunctionT function) : function_(std::move(function))
|
||||
CustomMF_SI_SI_SO(const char *name, FunctionT function) : function_(std::move(function))
|
||||
{
|
||||
MFSignatureBuilder signature{name};
|
||||
signature.single_input<In1>("In1");
|
||||
@@ -103,7 +103,7 @@ class CustomMF_SI_SI_SO : public MultiFunction {
|
||||
}
|
||||
|
||||
template<typename ElementFuncT>
|
||||
CustomMF_SI_SI_SO(StringRef name, ElementFuncT element_fn)
|
||||
CustomMF_SI_SI_SO(const char *name, ElementFuncT element_fn)
|
||||
: CustomMF_SI_SI_SO(name, CustomMF_SI_SI_SO::create_function(element_fn))
|
||||
{
|
||||
}
|
||||
@@ -150,7 +150,7 @@ class CustomMF_SI_SI_SI_SO : public MultiFunction {
|
||||
MFSignature signature_;
|
||||
|
||||
public:
|
||||
CustomMF_SI_SI_SI_SO(StringRef name, FunctionT function) : function_(std::move(function))
|
||||
CustomMF_SI_SI_SI_SO(const char *name, FunctionT function) : function_(std::move(function))
|
||||
{
|
||||
MFSignatureBuilder signature{name};
|
||||
signature.single_input<In1>("In1");
|
||||
@@ -162,7 +162,7 @@ class CustomMF_SI_SI_SI_SO : public MultiFunction {
|
||||
}
|
||||
|
||||
template<typename ElementFuncT>
|
||||
CustomMF_SI_SI_SI_SO(StringRef name, ElementFuncT element_fn)
|
||||
CustomMF_SI_SI_SI_SO(const char *name, ElementFuncT element_fn)
|
||||
: CustomMF_SI_SI_SI_SO(name, CustomMF_SI_SI_SI_SO::create_function(element_fn))
|
||||
{
|
||||
}
|
||||
@@ -211,7 +211,7 @@ class CustomMF_SI_SI_SI_SI_SO : public MultiFunction {
|
||||
MFSignature signature_;
|
||||
|
||||
public:
|
||||
CustomMF_SI_SI_SI_SI_SO(StringRef name, FunctionT function) : function_(std::move(function))
|
||||
CustomMF_SI_SI_SI_SI_SO(const char *name, FunctionT function) : function_(std::move(function))
|
||||
{
|
||||
MFSignatureBuilder signature{name};
|
||||
signature.single_input<In1>("In1");
|
||||
@@ -224,7 +224,7 @@ class CustomMF_SI_SI_SI_SI_SO : public MultiFunction {
|
||||
}
|
||||
|
||||
template<typename ElementFuncT>
|
||||
CustomMF_SI_SI_SI_SI_SO(StringRef name, ElementFuncT element_fn)
|
||||
CustomMF_SI_SI_SI_SI_SO(const char *name, ElementFuncT element_fn)
|
||||
: CustomMF_SI_SI_SI_SI_SO(name, CustomMF_SI_SI_SI_SI_SO::create_function(element_fn))
|
||||
{
|
||||
}
|
||||
@@ -265,7 +265,7 @@ template<typename Mut1> class CustomMF_SM : public MultiFunction {
|
||||
MFSignature signature_;
|
||||
|
||||
public:
|
||||
CustomMF_SM(StringRef name, FunctionT function) : function_(std::move(function))
|
||||
CustomMF_SM(const char *name, FunctionT function) : function_(std::move(function))
|
||||
{
|
||||
MFSignatureBuilder signature{name};
|
||||
signature.single_mutable<Mut1>("Mut1");
|
||||
@@ -274,7 +274,7 @@ template<typename Mut1> class CustomMF_SM : public MultiFunction {
|
||||
}
|
||||
|
||||
template<typename ElementFuncT>
|
||||
CustomMF_SM(StringRef name, ElementFuncT element_fn)
|
||||
CustomMF_SM(const char *name, ElementFuncT element_fn)
|
||||
: CustomMF_SM(name, CustomMF_SM::create_function(element_fn))
|
||||
{
|
||||
}
|
||||
@@ -306,8 +306,8 @@ template<typename From, typename To> class CustomMF_Convert : public MultiFuncti
|
||||
|
||||
static MFSignature create_signature()
|
||||
{
|
||||
std::string name = CPPType::get<From>().name() + " to " + CPPType::get<To>().name();
|
||||
MFSignatureBuilder signature{std::move(name)};
|
||||
static std::string name = CPPType::get<From>().name() + " to " + CPPType::get<To>().name();
|
||||
MFSignatureBuilder signature{name.c_str()};
|
||||
signature.single_input<From>("Input");
|
||||
signature.single_output<To>("Output");
|
||||
return signature.build();
|
||||
@@ -372,9 +372,7 @@ template<typename T> class CustomMF_Constant : public MultiFunction {
|
||||
template<typename U> CustomMF_Constant(U &&value) : value_(std::forward<U>(value))
|
||||
{
|
||||
MFSignatureBuilder signature{"Constant"};
|
||||
std::stringstream ss;
|
||||
ss << value_;
|
||||
signature.single_output<T>(ss.str());
|
||||
signature.single_output<T>("Value");
|
||||
signature_ = signature.build();
|
||||
this->set_signature(&signature_);
|
||||
}
|
||||
@@ -414,9 +412,7 @@ class CustomMF_DefaultOutput : public MultiFunction {
|
||||
MFSignature signature_;
|
||||
|
||||
public:
|
||||
CustomMF_DefaultOutput(StringRef name,
|
||||
Span<MFDataType> input_types,
|
||||
Span<MFDataType> output_types);
|
||||
CustomMF_DefaultOutput(Span<MFDataType> input_types, Span<MFDataType> output_types);
|
||||
void call(IndexMask mask, MFParams params, MFContext context) const override;
|
||||
};
|
||||
|
||||
@@ -425,7 +421,7 @@ class CustomMF_GenericCopy : public MultiFunction {
|
||||
MFSignature signature_;
|
||||
|
||||
public:
|
||||
CustomMF_GenericCopy(StringRef name, MFDataType data_type);
|
||||
CustomMF_GenericCopy(MFDataType data_type);
|
||||
void call(IndexMask mask, MFParams params, MFContext context) const override;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user