-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Remove buffer to decrease copy when encode NSString #50
Conversation
Have you run the baseline test before & after this modification? Is there any difference for NSString encoding? Logically speaking, it will be faster after this optimization. It's better to know. |
iOS/MMKV/MMKV/MiniPBCoder.mm
Outdated
NSData *buffer = [NSData dataWithBytes:m_formatBuffer length:realSize]; | ||
encodeItem->value.tmpObjectValue = (void *) CFBridgingRetain(buffer); | ||
NSData *buffer = [str dataUsingEncoding:NSUTF8StringEncoding]; | ||
encodeItem->value.tmpObjectValue = (__bridge_retained void *) buffer; |
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.
Keep indentation aligned please.
@lingol Yes, it's more faster, but TBO, using baseline test result to compare is unfair, because this optimize only have benefits about 10ms under 10000 times, every time I run test, it's hard to figure out wether it works, because the total time of baseline test ranges from 300ms to 400ms. So I used instrument to profile, but you know The new way, |
m_formatBuffer
is not needed, leads to additionalmalloc
and times ofcopy
.