Apr 1, 2020

[Go] zerolog library code dig

diode library dig:



The rest of zerolog code is straight forward and clean, lesson learned:
  • use sync.Pool to reuse object, should normalize the instance size before putting it back to sync.Pool
  • use embedded struct technique to extend interface. (Used in my Actor project)
  • use anonymous interface as generic type, cast back to proper interface and make the function call.
  • Go, same as C++, C, default copy by value. memcpy is fast, use it as your friend.
    e.g
    type Run struct{
     data *Data
     runnerInterface
    }
    Copy of Run instance is fast with the size of 8 bytes(ptr) + 16 bytes(interface)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.