From 079803eb0e1ea6c0cb7c6740aa29fe26fcc95d82 Mon Sep 17 00:00:00 2001 From: Yuta Iwama Date: Wed, 14 Aug 2019 15:43:37 +0900 Subject: [PATCH] Add hash method. no need to compare all varaible https://github.com/ruby/ruby/blob/0623e2b7cc621b1733a760b72af246b06c30cf96/struct.c#L1200-L1203 Signed-off-by: Yuta Iwama --- lib/fluent/plugin/buffer.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/fluent/plugin/buffer.rb b/lib/fluent/plugin/buffer.rb index fbf3559436..8d24a0d3f8 100644 --- a/lib/fluent/plugin/buffer.rb +++ b/lib/fluent/plugin/buffer.rb @@ -133,6 +133,15 @@ def <=>(o) cmp_variables(variables, variables2) end end + + # This is an optimization code. Current Struct's implementation is comparing all data. + # https://github.com/ruby/ruby/blob/0623e2b7cc621b1733a760b72af246b06c30cf96/struct.c#L1200-L1203 + # Actually this overhead is very small but this class is generated *per chunk* (and used in hash object). + # This means that this class is one of the most called object in Fluentd. + # See https://github.com/fluent/fluentd/pull/2560 + def hash + timekey.object_id + end end # for tests