Skip to content

Commit 10c09d0

Browse files
committed
allow yaml parser and visitor to be garbage collected
When loading a YAML dictionary the YamlFile class will store a YAML visitor and a parser. This means that after "read_file_into_dictionary" is called the Psych:Parser will keep the object tree that was used to parse and navigate the YAML document, even after the resulting Hash dictionary is created. While the memory required to parse the YAML dictionary is still required, we can change the YamlFile class to allow the Psych::Parser garbage collection, freeing a significant amount of memory from the heap.
1 parent 31d4484 commit 10c09d0

File tree

3 files changed

+10
-7
lines changed

3 files changed

+10
-7
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## 3.4.3
2+
- Allow YamlFile's Psych::Parser and Visitor instances to be garbage collected [#104](https://github.com/logstash-plugins/logstash-filter-translate/pull/104)
3+
14
## 3.4.2
25
- Fixed JRuby 9.4 compatibility issue[#98](https://github.com/logstash-plugins/logstash-filter-translate/pull/98)
36

lib/logstash/filters/dictionary/yaml_file.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@ class YamlFile < File
88
protected
99

1010
def initialize_for_file_type(**file_type_args)
11-
@visitor = YamlVisitor.create
12-
13-
@parser = Psych::Parser.new(Psych::TreeBuilder.new)
14-
@parser.code_point_limit = file_type_args[:yaml_code_point_limit]
11+
@yaml_code_point_limit = file_type_args[:yaml_code_point_limit]
1512
end
1613

1714
def read_file_into_dictionary
15+
visitor = YamlVisitor.create
16+
parser = Psych::Parser.new(Psych::TreeBuilder.new)
17+
parser.code_point_limit = @yaml_code_point_limit
1818
# low level YAML read that tries to create as
1919
# few intermediate objects as possible
2020
# this overwrites the value at key
2121
yaml_string = IO.read(@dictionary_path, :mode => 'r:bom|utf-8')
22-
@parser.parse(yaml_string, @dictionary_path)
23-
@visitor.accept_with_dictionary(@dictionary, @parser.handler.root)
22+
parser.parse(yaml_string, @dictionary_path)
23+
visitor.accept_with_dictionary(@dictionary, parser.handler.root)
2424
end
2525
end
2626
end end end

logstash-filter-translate.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Gem::Specification.new do |s|
22

33
s.name = 'logstash-filter-translate'
4-
s.version = '3.4.2'
4+
s.version = '3.4.3'
55
s.licenses = ['Apache License (2.0)']
66
s.summary = "Replaces field contents based on a hash or YAML file"
77
s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"

0 commit comments

Comments
 (0)