-
Notifications
You must be signed in to change notification settings - Fork 1.4k
[core] Simplify ErrorHandler implementation #19395
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
base: master
Are you sure you want to change the base?
Conversation
The current implementation uses a stack-allocated buffer + an optionally- allocated thread local heap buffer for vsnprintf. This likely was made to avoid heap allocating whenever not necessary (i.e. in the majority of cases). However, a subsequent commit introduced a string `bp` that always performs the copy anyway. At this point the code can be simplified to avoid the double buffer and simply allocate straight into the string avoiding an extra copy.
7b3a187
to
d0b0494
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.
The reasoning makes sense to me.
yes, this is the case (In particular this is useful because of the not so rare case where the ErrorHandler ends up being called during signal handling).
humm :( That is actually bad. The original PR #5855, the reviewers completely missed this unexpected but significant change (the commit is "remove gEnv and gSystem deps from TError " ...). We should revert the part of the commit that introduce the unwanted memory allocation rather than doubling down on it ... (or alternatively re-implement the function so that it returns in another way to having no memory allocation in most cases). |
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.
See comment on memory allocation
Can you explain why you think this is critical? After all, we are talking about an error handler, so by definition this should not be on the critical path. |
@hahnjo unfortunately the ErrorHandler is also called on |
... which wasn't a problem for five years... |
Nobody complained about it for five years, which is a weaker statement. But I am also not convinced it's something we actually need to address... |
Ping @pcanal |
The current implementation uses a stack-allocated buffer + an optionally- allocated thread local heap buffer for vsnprintf. This likely was made to avoid heap allocating whenever not necessary (i.e. in the majority of cases).
However, a subsequent commit introduced a string
bp
that always performs the copy anyway. At this point the code can be simplified to avoid the double buffer and simply allocate straight into the string avoiding an extra copy.