You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We updated from version 1.17.0 to 1.20.3 and saw some large code size additons.
We tracked them down to #1042 and #1183. After some thinking, I came up with an idea to reduce the generated code:
Currently, depending on the type of a field, code like the following is generated:
try { if let v = _storage._singularInt32 {
try visitor.visitSingularInt32Field(value: v, fieldNumber: 1)
} }()
Through the introduction of an helper function on Vistor that performs the optional unwrapping, we could generate the following code instead:
extension Visitor {
mutating func visitSingularInt32Field(optionalValue value: Int32?, fieldNumber: Int) throws {
if let value {
try visitSingularInt32Field(value: value, fieldNumber: fieldNumber)
}
}
}
This would move the optional checks out of the traverse method and its closures, but it requires one additional call to the helper function.
I did some naive tests of this apporach on compiler explorer and it seems to reduce the generated machine code for my simplified example.
I am happy to contribute an implementation, but wanted to propose and discuss the change first.
I will also verify that there is a code size reduction for optimized builds as well.
(The approach should work on the 1.x branch as well as main.)
The text was updated successfully, but these errors were encountered:
Just confirming first, you are talking about size changes in release builds? How much of a size change for how many/how complex of messages?
There's also some discussion going on on #861 about changing things to support a new behavior that also has the potential to change code sizes of things.
We updated from version 1.17.0 to 1.20.3 and saw some large code size additons.
We tracked them down to #1042 and #1183. After some thinking, I came up with an idea to reduce the generated code:
Currently, depending on the type of a field, code like the following is generated:
Through the introduction of an helper function on
Vistor
that performs the optional unwrapping, we could generate the following code instead:The extension for Vistor looks like this:
This would move the optional checks out of the
traverse
method and its closures, but it requires one additional call to the helper function.I did some naive tests of this apporach on compiler explorer and it seems to reduce the generated machine code for my simplified example.
I am happy to contribute an implementation, but wanted to propose and discuss the change first.
I will also verify that there is a code size reduction for optimized builds as well.
(The approach should work on the 1.x branch as well as main.)
The text was updated successfully, but these errors were encountered: