Geometry Nodes: use stringref instead of string in logger

This reduces logging overhead. The performance difference is only
significant when there are many fast nodes. In my test file with many
math nodes, the performance improved from 720ms to 630ms.
This commit is contained in:
Jacques Lucke 2022-09-17 12:08:43 +02:00
parent 1810b1e4c8
commit 7549e0c5ae
7 changed files with 40 additions and 33 deletions

View File

@ -1770,7 +1770,7 @@ struct NodeExtraInfoRow {
};
struct NamedAttributeTooltipArg {
Map<std::string, geo_log::NamedAttributeUsage> usage_by_attribute;
Map<StringRefNull, geo_log::NamedAttributeUsage> usage_by_attribute;
};
static char *named_attribute_tooltip(bContext *UNUSED(C), void *argN, const char *UNUSED(tip))
@ -1824,7 +1824,7 @@ static char *named_attribute_tooltip(bContext *UNUSED(C), void *argN, const char
}
static NodeExtraInfoRow row_from_used_named_attribute(
const Map<std::string, geo_log::NamedAttributeUsage> &usage_by_attribute_name)
const Map<StringRefNull, geo_log::NamedAttributeUsage> &usage_by_attribute_name)
{
const int attributes_num = usage_by_attribute_name.size();

View File

@ -1760,7 +1760,7 @@ static void internal_dependencies_panel_draw(const bContext *UNUSED(C), Panel *p
}
tree_log->ensure_used_named_attributes();
const Map<std::string, NamedAttributeUsage> &usage_by_attribute =
const Map<StringRefNull, NamedAttributeUsage> &usage_by_attribute =
tree_log->used_named_attributes;
if (usage_by_attribute.is_empty()) {

View File

@ -237,13 +237,13 @@ class GeoNodeExecParams {
* Add an error message displayed at the top of the node when displaying the node tree,
* and potentially elsewhere in Blender.
*/
void error_message_add(const NodeWarningType type, std::string message) const;
void error_message_add(const NodeWarningType type, StringRef message) const;
std::string attribute_producer_name() const;
void set_default_remaining_outputs();
void used_named_attribute(std::string attribute_name, NamedAttributeUsage usage);
void used_named_attribute(StringRef attribute_name, NamedAttributeUsage usage);
private:
/* Utilities for detecting common errors at when using this class. */

View File

@ -169,37 +169,37 @@ using TimePoint = Clock::time_point;
class GeoTreeLogger {
public:
std::optional<ComputeContextHash> parent_hash;
std::optional<std::string> group_node_name;
std::optional<StringRefNull> group_node_name;
Vector<ComputeContextHash> children_hashes;
LinearAllocator<> *allocator = nullptr;
struct WarningWithNode {
std::string node_name;
StringRefNull node_name;
NodeWarning warning;
};
struct SocketValueLog {
std::string node_name;
std::string socket_identifier;
StringRefNull node_name;
StringRefNull socket_identifier;
destruct_ptr<ValueLog> value;
};
struct NodeExecutionTime {
std::string node_name;
StringRefNull node_name;
TimePoint start;
TimePoint end;
};
struct ViewerNodeLogWithNode {
std::string node_name;
StringRefNull node_name;
destruct_ptr<ViewerNodeLog> viewer_log;
};
struct AttributeUsageWithNode {
std::string node_name;
std::string attribute_name;
StringRefNull node_name;
StringRefNull attribute_name;
NamedAttributeUsage usage;
};
struct DebugMessage {
std::string node_name;
std::string message;
StringRefNull node_name;
StringRefNull message;
};
Vector<WarningWithNode> node_warnings;
@ -235,12 +235,12 @@ class GeoNodeLog {
*/
std::chrono::nanoseconds run_time{0};
/** Maps from socket identifiers to their values. */
Map<std::string, ValueLog *> input_values_;
Map<std::string, ValueLog *> output_values_;
Map<StringRefNull, ValueLog *> input_values_;
Map<StringRefNull, ValueLog *> output_values_;
/** Maps from attribute name to their usage flags. */
Map<std::string, NamedAttributeUsage> used_named_attributes;
Map<StringRefNull, NamedAttributeUsage> used_named_attributes;
/** Messages that are used for debugging purposes during development. */
Vector<std::string> debug_messages;
Vector<StringRefNull> debug_messages;
GeoNodeLog();
~GeoNodeLog();
@ -269,12 +269,12 @@ class GeoTreeLog {
bool reduced_debug_messages_ = false;
public:
Map<std::string, GeoNodeLog> nodes;
Map<std::string, ViewerNodeLog *, 0> viewer_node_logs;
Map<StringRefNull, GeoNodeLog> nodes;
Map<StringRefNull, ViewerNodeLog *, 0> viewer_node_logs;
Vector<NodeWarning> all_warnings;
std::chrono::nanoseconds run_time_sum{0};
Vector<const GeometryAttributeInfo *> existing_attributes;
Map<std::string, NamedAttributeUsage> used_named_attributes;
Map<StringRefNull, NamedAttributeUsage> used_named_attributes;
GeoTreeLog(GeoModifierLog *modifier_log, Vector<GeoTreeLogger *> tree_loggers);
~GeoTreeLog();

View File

@ -134,7 +134,8 @@ class LazyFunctionForGeometryNode : public LazyFunction {
if (geo_eval_log::GeoModifierLog *modifier_log = user_data->modifier_data->eval_log) {
geo_eval_log::GeoTreeLogger &tree_logger = modifier_log->get_local_tree_logger(
*user_data->compute_context);
tree_logger.node_execution_times.append({node_.name, start_time, end_time});
tree_logger.node_execution_times.append(
{tree_logger.allocator->copy_string(node_.name), start_time, end_time});
}
}
};

View File

@ -148,7 +148,9 @@ void GeoTreeLogger::log_value(const bNode &node, const bNodeSocket &socket, cons
auto store_logged_value = [&](destruct_ptr<ValueLog> value_log) {
auto &socket_values = socket.in_out == SOCK_IN ? this->input_socket_values :
this->output_socket_values;
socket_values.append({node.name, socket.identifier, std::move(value_log)});
socket_values.append({this->allocator->copy_string(node.name),
this->allocator->copy_string(socket.identifier),
std::move(value_log)});
};
auto log_generic_value = [&](const CPPType &type, const void *value) {
@ -194,7 +196,7 @@ void GeoTreeLogger::log_viewer_node(const bNode &viewer_node,
log->geometry = geometry;
log->field = field;
log->geometry.ensure_owns_direct_data();
this->viewer_node_logs.append({viewer_node.name, std::move(log)});
this->viewer_node_logs.append({this->allocator->copy_string(viewer_node.name), std::move(log)});
}
void GeoTreeLog::ensure_node_warnings()
@ -315,11 +317,11 @@ void GeoTreeLog::ensure_used_named_attributes()
return;
}
auto add_attribute = [&](const StringRef node_name,
const StringRef attribute_name,
auto add_attribute = [&](const StringRefNull node_name,
const StringRefNull attribute_name,
const NamedAttributeUsage &usage) {
this->nodes.lookup_or_add_as(node_name).used_named_attributes.lookup_or_add_as(attribute_name,
usage) |= usage;
this->nodes.lookup_or_add_default(node_name).used_named_attributes.lookup_or_add(
attribute_name, usage) |= usage;
this->used_named_attributes.lookup_or_add_as(attribute_name, usage) |= usage;
};

View File

@ -13,18 +13,22 @@
namespace blender::nodes {
void GeoNodeExecParams::error_message_add(const NodeWarningType type, std::string message) const
void GeoNodeExecParams::error_message_add(const NodeWarningType type,
const StringRef message) const
{
if (geo_eval_log::GeoTreeLogger *tree_logger = this->get_local_tree_logger()) {
tree_logger->node_warnings.append({node_.name, {type, std::move(message)}});
tree_logger->node_warnings.append({tree_logger->allocator->copy_string(node_.name),
{type, tree_logger->allocator->copy_string(message)}});
}
}
void GeoNodeExecParams::used_named_attribute(std::string attribute_name,
void GeoNodeExecParams::used_named_attribute(const StringRef attribute_name,
const NamedAttributeUsage usage)
{
if (geo_eval_log::GeoTreeLogger *tree_logger = this->get_local_tree_logger()) {
tree_logger->used_named_attributes.append({node_.name, std::move(attribute_name), usage});
tree_logger->used_named_attributes.append({tree_logger->allocator->copy_string(node_.name),
tree_logger->allocator->copy_string(attribute_name),
usage});
}
}