This repository has been archived on 2023-10-09. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
blender-archive/source/blender/blenkernel/BKE_compute_contexts.hh
Jacques Lucke a09accb496 Geometry Nodes: speedup compute context hash generation
Whenever a node group is entered during evaluation, a new compute
context is entered which has a corresponding hash. When node groups
are entered and exited a lot, this can have some overhead. In my test
file with ~100.000 node group invocations, this patch improves performance
by about 7%.

The speedup is achieved in two ways:
* Avoid computing the same hash twice by caching it.
* Invoke the hashing algorithm (md5 currently) only once instead of twice.
2022-12-29 20:46:05 +01:00

61 lines
1.5 KiB
C++

/* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
/**
* This file implements some specific compute contexts for concepts in Blender.
*/
#include <optional>
#include "BLI_compute_context.hh"
struct bNode;
namespace blender::bke {
class ModifierComputeContext : public ComputeContext {
private:
static constexpr const char *s_static_type = "MODIFIER";
/**
* Use modifier name instead of something like `session_uuid` for now because:
* - It's more obvious that the name matches between the original and evaluated object.
* - We might want that the context hash is consistent between sessions in the future.
*/
std::string modifier_name_;
public:
ModifierComputeContext(const ComputeContext *parent, std::string modifier_name);
private:
void print_current_in_line(std::ostream &stream) const override;
};
class NodeGroupComputeContext : public ComputeContext {
private:
static constexpr const char *s_static_type = "NODE_GROUP";
int32_t node_id_;
#ifdef DEBUG
std::string debug_node_name_;
#endif
public:
NodeGroupComputeContext(const ComputeContext *parent,
int32_t node_id,
const std::optional<ComputeContextHash> &cached_hash = {});
NodeGroupComputeContext(const ComputeContext *parent, const bNode &node);
int32_t node_id() const
{
return node_id_;
}
private:
void print_current_in_line(std::ostream &stream) const override;
};
} // namespace blender::bke