Skip to content

Minor performance improvements #4294

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/fluent/plugin/buffer/file_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/fluent/plugin/buffer/file_single_chunk.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions lib/fluent/registry.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,31 +60,31 @@ 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|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: filter_map is available as of Ruby 2.7.
Recently we changed required Ruby version to 2.7, so it's no problem to use it: #4288

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
require files.max
return
end
end

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
require files.max
return
end

Expand Down
2 changes: 1 addition & 1 deletion lib/fluent/unique_id.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down