Closed
Description
I'm using the message in the cache and flush them into file/db at some time. it's small in memory and fast when write files.
But not any more after the XXX_ fields were put in generated structs.
message SmallDecimal {
bool neg = 1;
uint64 value = 2;
int32 exp = 3;
}
message Order {
uint64 orderId = 1;
SmallDecimal amount = 2;
SmallDecimal price = 3;
uint64 timestamp = 4;
}
type NoXXXSmallDecimal struct {
neg bool
value uint64
exp int32
}
type NoXXXOrder struct {
orderId uint64
amount *NoXXXSmallDecimal
price *NoXXXSmallDecimal
timestamp uint64
}
func main() {
fmt.Println("Sizeof SmallDecimal", unsafe.Sizeof(SmallDecimal{}))
fmt.Println("Sizeof Order", unsafe.Sizeof(Order{}))
fmt.Println("Sizeof NoXXXSmallDecimal", unsafe.Sizeof(NoXXXSmallDecimal{}))
fmt.Println("Sizeof NoXXXOrder", unsafe.Sizeof(NoXXXOrder{}))
}
I have do a lot of things to reduce the copy of memory and the cost of memory.
Sizeof SmallDecimal 56
Sizeof Order 64
Sizeof NoXXXSmallDecimal 24
Sizeof NoXXXOrder 32
What it would happen if i remove the XXX_* field by comment generateInternalStructFields in proto-gen-go?
Metadata
Metadata
Assignees
Labels
No labels