Skip to content

Commit

Permalink
Merge pull request #2560 from ganmacs/add-hash-to-metadata
Browse files Browse the repository at this point in the history
Add hash method to metadata to speed up comparing it in a hash key
  • Loading branch information
repeatedly authored Aug 21, 2019
2 parents a2a164e + 079803e commit a9ba3f8
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/fluent/plugin/buffer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit a9ba3f8

Please sign in to comment.