From 91c916f9c6263d1c437ec7eda222d7f6b8817175 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Xavier=20Dupr=C3=A9?= Date: Wed, 11 Sep 2024 19:41:04 +0200 Subject: [PATCH] Improve hash_function used by TreeEnsemble (#22043) ### Description unordered_map are implemented in a different way on VisualStudio and gcc. It seems that inserting consecutive keys has a poor performance on Windows. ### Motivation and Context Improve the performance of onnxruntime when initializing trees. --- onnxruntime/core/providers/cpu/ml/tree_ensemble_aggregator.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/onnxruntime/core/providers/cpu/ml/tree_ensemble_aggregator.h b/onnxruntime/core/providers/cpu/ml/tree_ensemble_aggregator.h index b9f3050e59..34c6db6198 100644 --- a/onnxruntime/core/providers/cpu/ml/tree_ensemble_aggregator.h +++ b/onnxruntime/core/providers/cpu/ml/tree_ensemble_aggregator.h @@ -23,7 +23,9 @@ struct TreeNodeElementId { } struct hash_fn { std::size_t operator()(const TreeNodeElementId& key) const { - return static_cast(static_cast(key.tree_id) << 32 | static_cast(key.node_id)); + // unordered_map has poor performance on Windows when inserting consecutive keys. + // keys are usually inserted with key.node_id being incremented at each iteration. + return static_cast(static_cast(key.tree_id) | static_cast(key.node_id) << 32); } }; };