Skip to content

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

Closed
@lvhuat

Description

@lvhuat

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions