-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
BAAS-23396: add strings overhead to mem usage calculations #86
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What a wonderful find! I only have one question but not really related to your change.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! nothing else to add on my side. Great find!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🤑
35e28b0
to
78f13e3
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 🥇 I just have one question about the MemUsageLimitExceeded
check.
array.go
Outdated
} | ||
if exceeded := ctx.MemUsageLimitExceeded(total); exceeded { | ||
return total, nil | ||
if exceeded := ctx.MemUsageLimitExceeded(memUsage); exceeded { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] should we use mewMemUsage
instead of memUsage
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good question, eventually the newMem and mem will have the same value but we are using this PR to collect data about the gap between the two values for customers to get an idea of the impact of this change. Until we apply this new changes all the memory logic will rely on the current memUsage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just had some questions and optional things.
string_unicode_test.go
Outdated
{ | ||
name: "should have a value given the length of the string", | ||
val: unicodeString{' ', 'y', 'o'}, | ||
expected: 2, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] why 2 instead of 3? Does space not count?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When this gets converted to a string (see the String() method on this type) we skip the first item which can represent the little-indian/big-indian convention but not the actual content of the string. Not 100% that's what the first char is used for but I know that even comparisons between strings skip the fist char if it's a unicode string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Will be interesting to see the results for customers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
nv = new MyNativeVal() | ||
checkMem();`, | ||
testNativeValueMemUsage + 2, | ||
expectedSizeDiff: testNativeValueMemUsage + | ||
2, // "nv" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[q] what does nv
mean here? Native Value?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is for the variable name nv
, so it's the len("nv")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
…as separate mem usage value (#86)
This is a small ma pretty important change. Strings in go have an overhead of 16bytes, currently an empty string adds up to 0 bytes from the way we calculate memory usage which is not correct. With this change every native string or object key (which are also strings) will also account for the overhead defined in
SizeString
.EDIT
To understand the impact of this change all
MemUsage
functions return the existing value + an adjusted one. This will help us understand the impact of such a change before we roll it out to customers. I split the commit logically for easier review but beware that the whole test suite only passes with the last commits.Generally I noticed a few missing
nil
checks and other incorrect MemUsage functions, the diff should be easy to spot from the single commits.