freecache
freecache copied to clipboard
Use `interface{}` as value can reduce GC and save CPU
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?
Store many interface{}
in memory will cause big GC impact.
GC overhead is proportional to the number of long-lived objects.
Store many
interface{}
in memory will cause big GC impact. GC overhead is proportional to the number of long-lived objects.
您好,为什么内存中存储大量 interface{} 会对gc造成很大的影响,可以给一个思考这个问题的思路么, 谢谢您!
@SmileEye You can read this blog https://blog.golang.org/ismmkeynote
@coocood Thank you for your reply. I will read this blog carefully.
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?