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

I think the XXX_ field is real bad idea,what happen if i remove them from the code #856

Closed
lvhuat opened this issue May 23, 2019 · 1 comment

Comments

@lvhuat
Copy link

lvhuat commented May 23, 2019

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?

@dsnet
Copy link
Member

dsnet commented May 23, 2019

The XXX_unrecognized fields are to support unknown fields. If you're using proto3, they were a proto language change added by protocolbuffers/protobuf#272.

I filed two other issues to address the root problem you are hitting: #857, #858

@dsnet dsnet closed this as completed May 23, 2019
@golang golang locked and limited conversation to collaborators Jun 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants