-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Small message buffer optimization for SDL_log and SDL_assert #5584
Conversation
d6cc791
to
99f5f1d
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.
I think this is a good idea, with some tweaks, but the mutex needs to stay regardless.
I like the idea that we're no longer limited on log message size. Let's do it! :) |
I appreciate the review, and I have pushed changes addressing Ryan's comments. As for being limited on size, do you want me to actually remove Starting to second-guess myself, maybe this isn't worth it and using a static buffer with locks around it is better overall. Please be very specific in what you want, and I'll get on it. |
For short messages, use a stack buffer that is significantly smaller than SDL_MAX_LOG_MESSAGE. For larger messages, fall back to allocation.
For short messages, use a stack buffer that is significantly smaller than SDL_MAX_LOG_MESSAGE. The rationale for this is that we don't want to risk blowing the stack, while at the same time we would like to not put pressure on the memory allocator unless absolutely necessary.
99f5f1d
to
47e97a1
Compare
Let's use a static buffer for messages <= 256 bytes, and malloc for longer lines. I'm not too worried about the unbounded pointer case, the likelihood of not getting a zero for a long time is pretty low, and malloc() will fail for really really long lines. We free the pointer almost immediately, so I'm not worried about introducing any issues with consuming too much memory here. |
Okay, I'll rework the code to no longer truncate log messages. Same for the assert code? |
Log messages are no longer truncated to SDL_MAX_LOG_MESSAGE.
Messages are no longer truncated to SDL_MAX_LOG_MESSAGE.
I have pushed the changes to allow for 'unbounded' log and assert messages. I have not touched this Apple code in
|
I'll go ahead and fix this. |
This works in conjunction with #5584
Eloj convinced me; 256 bytes is good, and let's stack allocate it and see what happens. |
@eloj, I think this PR is good to go. |
I saw the discussion on 2a42952 and subsequent commits, and thought this sort of solution could be another approach worth trying.
After forgetting I had to copy the
va_list
I spent way too much time on this... but that's on me, if you don't like the approach it goes in the bin.Pros:
No mutex required (unless I'm missing something?)Cons:
vsnprintf
for large messages.SDL_MAX_LOG_MESSAGE_STACK
toSDL_MAX_LOG_MESSAGE
and avoid the extra allocation.