From 2ee2779fb2689510b3d908d9fac14f0f600d9713 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Fri, 8 Sep 2023 23:37:33 +0200 Subject: [PATCH 1/4] perf: use filter_map instead of map.compact MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Lukašík --- lib/fluent/registry.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/fluent/registry.rb b/lib/fluent/registry.rb index 9e473c27fd..d74439808c 100644 --- a/lib/fluent/registry.rb +++ b/lib/fluent/registry.rb @@ -60,10 +60,10 @@ def search(type) # search from additional plugin directories if @dir_search_prefix path = "#{@dir_search_prefix}#{type}" - files = @paths.map { |lp| + files = @paths.filter_map { |lp| lpath = File.expand_path(File.join(lp, "#{path}.rb")) File.exist?(lpath) ? lpath : nil - }.compact + } unless files.empty? # prefer newer version require files.sort.last @@ -74,14 +74,14 @@ def search(type) path = "#{@search_prefix}#{type}" # prefer LOAD_PATH than gems - files = $LOAD_PATH.map { |lp| + files = $LOAD_PATH.filter_map { |lp| if lp == FLUENT_LIB_PATH nil else lpath = File.expand_path(File.join(lp, "#{path}.rb")) File.exist?(lpath) ? lpath : nil end - }.compact + } unless files.empty? # prefer newer version require files.sort.last From 31c5439628d7f188a4d79ba0f25176932ac89dd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Fri, 8 Sep 2023 23:38:42 +0200 Subject: [PATCH 2/4] perf: Use max instead of sort...last MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Lukašík --- lib/fluent/registry.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fluent/registry.rb b/lib/fluent/registry.rb index d74439808c..b321f6f748 100644 --- a/lib/fluent/registry.rb +++ b/lib/fluent/registry.rb @@ -66,7 +66,7 @@ def search(type) } unless files.empty? # prefer newer version - require files.sort.last + require files.max return end end @@ -84,7 +84,7 @@ def search(type) } unless files.empty? # prefer newer version - require files.sort.last + require files.max return end From 79220ab40c45f9316ccb7879e1490accf3052f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Fri, 8 Sep 2023 23:39:38 +0200 Subject: [PATCH 3/4] perf: use unpack1 instead of unpack..first MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Lukašík --- lib/fluent/plugin/buffer/file_chunk.rb | 2 +- lib/fluent/unique_id.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/fluent/plugin/buffer/file_chunk.rb b/lib/fluent/plugin/buffer/file_chunk.rb index 06bbf017c2..7930574a58 100644 --- a/lib/fluent/plugin/buffer/file_chunk.rb +++ b/lib/fluent/plugin/buffer/file_chunk.rb @@ -399,7 +399,7 @@ def restore_metadata_with_new_format(chunk) end if chunk.slice(0, 2) == BUFFER_HEADER - size = chunk.slice(2, 4).unpack('N').first + size = chunk.slice(2, 4).unpack1('N') if size return Fluent::MessagePackFactory.msgpack_unpacker(symbolize_keys: true).feed(chunk.slice(6, size)).read rescue nil end diff --git a/lib/fluent/unique_id.rb b/lib/fluent/unique_id.rb index 060c2e2290..7dce181418 100644 --- a/lib/fluent/unique_id.rb +++ b/lib/fluent/unique_id.rb @@ -23,7 +23,7 @@ def self.generate end def self.hex(unique_id) - unique_id.unpack('H*').first + unique_id.unpack1('H*') end module Mixin From a21dcab37d395938185a31f3aefa27b4f36a9085 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=A0imon=20Luka=C5=A1=C3=ADk?= Date: Fri, 8 Sep 2023 23:40:54 +0200 Subject: [PATCH 4/4] perf: use URI::DEFAULT_PARSER instead of URI::Parser.new MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Šimon Lukašík --- lib/fluent/plugin/buffer/file_single_chunk.rb | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/fluent/plugin/buffer/file_single_chunk.rb b/lib/fluent/plugin/buffer/file_single_chunk.rb index 7225438af6..4cc9d6c625 100644 --- a/lib/fluent/plugin/buffer/file_single_chunk.rb +++ b/lib/fluent/plugin/buffer/file_single_chunk.rb @@ -238,17 +238,16 @@ def file_rename(file, old_path, new_path, callback = nil) callback.call(file) if callback end - URI_PARSER = URI::Parser.new ESCAPE_REGEXP = /[^-_.a-zA-Z0-9]/n def encode_key(metadata) k = @key ? metadata.variables[@key] : metadata.tag k ||= '' - URI_PARSER.escape(k, ESCAPE_REGEXP) + URI::DEFAULT_PARSER.escape(k, ESCAPE_REGEXP) end def decode_key(key) - URI_PARSER.unescape(key) + URI::DEFAULT_PARSER.unescape(key) end def create_new_chunk(path, metadata, perm)