Replies: 1 comment 2 replies
-
|
Assuming the following memory allocations:
removing the indicated fields, the size of the struct should be reduced by 51 bytes (without considering the alignment), initializing a map should allocate 48 bytes, so we save 3 bytes for each connected client. If we'll add other fields to the clientHandler struct the memory save will increase in the future. If we switch I did some quick benchmarks Here are the results (after converting from int to int8 all the enum fields mentioned above): so no real benefit. If I don't convert the enum from int to int8 we have these results (clientHandlerWithMap is better aligned, so 16 bytes are saved): Based on these results, my opinion is it doesn't matter (at least for now). However, if you prefer, I have no problem to send a patch that adds this feature. P.S. I'm on a laptop ns/op will vary between runs, sometime ns/op is smaller for BenchmarkClientHandlerWithMap than BenchmarkClientHandler |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Mostly for @drakkan (but everyone else is welcome),
With #334 we are adding one more field to the
clientHandlerstruct.And many of these fields are optional ones, in the sense that they are frequently never filled and could be used to a default value:
clntcan often be unspecifiedctxRnfris used during the renamingctxRestis used in the scope of file write restartdebugis used only when we need debuggingtransferTLSandcontrolTLSselectedHashAlgowill often be not specified because HASH won't be usedSo I wonder if using a
map[string]interface{}ormap[int]interface{}wouldn't be a good option to not consume memory for parameters that are usually not specified.2 votes ·
Beta Was this translation helpful? Give feedback.
All reactions