Closed srijs closed 1 year ago
Patch coverage: 100.00
% and project coverage change: -0.28
:warning:
Comparison is base (
5777b55
) 75.63% compared to head (0dffcd0
) 75.36%.
:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Do you have feedback about the report comment? Let us know in this issue.
Thanks for the PR!
As an aside, I've also noticed that there are two other places where generics cause multiple copies of very large functions and/or sections of code: Visitor and FieldDescriptorLike. I am wondering whether you have considered switching the functions taking impls of these traits to use dyn traits instead? That seems like it has the potential to reduce code size somewhat further, but may need to be benchmarked due to the dynamic dispatch it'd introduce.
I think switching Visitor to dynamic dispatch should be fine, I don't expect building a descriptor pool to be a performance-critical operation.
FieldDescriptorLike is used in a lot of serialization/deserialization code where performance is a bit more important. We could potentially split out the common fields of FieldDescriptor and ExtensionDescriptor into a common struct that both codepaths can reference. Alternatively a simple enum of FieldDescriptor and ExtensionDescriptor might be worth benchmarking
Hi, thanks so much for putting together this crate, it's been super helpful in building dynamic gRPC functionality.
I'm overall very happy with
prost-reflect
, but while working on reducing the size of my binaries usingcargo bloat
I noticed that it was using significant space in the text section, both directly throughdecode_file_descriptor_set
anddecode
but also in the methods in my code callingdecode_file_descriptor_set
due to inlining.Trying to understand why this might be, I came across this optimization. The problem with the
build_files
method is that it takes a genericIntoIterator
, which means the function is monomorphized at multiple sites inDescriptorPool
. Because the logic insidebuild_files
becomes quite complex with the different visitors, this results in a decent amount of code bloat.The change I'm proposing here simply moves the bulk of the heavy logic into a non-polymorphic function (
build_files_deduped
) without changing any functionality whatsoever. This should be fully equivalent in terms of performance and behaviour, with the only difference being that the binary footprint of users of the crate should be significantly reduced.In my particular case, this change reduces the total binary size by ~86KiB, which represents a saving of more than 1/4 of the total code size attributable to
prost-reflect
(335.4KiB according tocargo bloat
before the optimization).As an aside, I've also noticed that there are two other places where generics cause multiple copies of very large functions and/or sections of code:
Visitor
andFieldDescriptorLike
. I am wondering whether you have considered switching the functions taking impls of these traits to usedyn
traits instead? That seems like it has the potential to reduce code size somewhat further, but may need to be benchmarked due to the dynamic dispatch it'd introduce.