Skip to content
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

Ruby: decoding an empty protocol buffer allocates objects for every field in that protobuf's descriptor #6496

Closed
fables-tales opened this issue Aug 12, 2019 · 2 comments
Assignees

Comments

@fables-tales
Copy link
Contributor

require 'google/protobuf'

Google::Protobuf::DescriptorPool.generated_pool.build do
  add_message "hi" do
    # vary this to see more or less allocations
    10.times do |i|
      optional :"resource_name_#{i}", :string, i+1
    end
  end
end

module Mod
  Hi = Google::Protobuf::DescriptorPool.generated_pool.lookup("hi").msgclass
end

h = Mod::Hi.new
data = Mod::Hi.encode(h)

# 4 GCs to force all allocated objects to either be removed
# or moved to the oldest generation
GC.start
GC.start
GC.start
GC.start

start_alloc = GC.stat
# uncomment either
#Mod::Hi.decode("")
#Mod::Hi.decode(data)
end_alloc = GC.stat

p end_alloc[:total_allocated_objects]-start_alloc[:total_allocated_objects]
@fables-tales
Copy link
Contributor Author

(Just dropped this in here from a hangout with @haberman)

@fables-tales fables-tales changed the title Ruby: decoding an empty protocol buffer allocates objects for every field in that . descriptor Ruby: decoding an empty protocol buffer allocates objects for every field in that protobuf's descriptor Aug 12, 2019
@haberman
Copy link
Member

Confirmed. This is specific to string fields. I have a fix for this here: #6502

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants