freecache icon indicating copy to clipboard operation
freecache copied to clipboard

Use `interface{}` as value can reduce GC and save CPU

Open hatlonely opened this issue 6 years ago • 5 comments

Because the value is only support []byte, we should serialize/unserialize our data each set/get operation, this will cost more CPU time. And the serialized/unserialized object will free which cause more GC. Why do we just use interface{} as value?

hatlonely avatar Jun 22 '18 03:06 hatlonely

Store many interface{} in memory will cause big GC impact. GC overhead is proportional to the number of long-lived objects.

coocood avatar Jun 22 '18 17:06 coocood

Store many interface{} in memory will cause big GC impact. GC overhead is proportional to the number of long-lived objects.

您好,为什么内存中存储大量 interface{} 会对gc造成很大的影响,可以给一个思考这个问题的思路么, 谢谢您!

SmileEye avatar Feb 25 '19 09:02 SmileEye

@SmileEye You can read this blog https://blog.golang.org/ismmkeynote

coocood avatar Feb 25 '19 10:02 coocood

@coocood Thank you for your reply. I will read this blog carefully.

SmileEye avatar Feb 25 '19 11:02 SmileEye

Store many interface{} in memory will cause big GC impact. GC overhead is proportional to the number of long-lived objects.

but still we need to encode/decode the object when i set/get items which on the other hand will use more CPU resource. Why not leave this choose for user?

lcken avatar Jan 03 '20 12:01 lcken