Skip to content

[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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

silverweed
Copy link
Contributor

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.

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.
Copy link
Member

@hahnjo hahnjo left a 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.

@pcanal
Copy link
Member

pcanal commented Jul 21, 2025

This likely was made to avoid heap allocating whenever not necessary (i.e. in the majority of cases).

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).

However, a subsequent commit introduced a string bp

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).

Copy link
Member

@pcanal pcanal left a 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

@hahnjo
Copy link
Member

hahnjo commented Jul 22, 2025

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).

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.

@silverweed
Copy link
Contributor Author

@hahnjo unfortunately the ErrorHandler is also called on Info and the likes, so it might actually be called repeatedly (although one might argue that the real performance killer in that case is I/O and not memory allocations...)

@hahnjo
Copy link
Member

hahnjo commented Jul 22, 2025

... which wasn't a problem for five years...

@silverweed
Copy link
Contributor Author

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...

@silverweed
Copy link
Contributor Author

Ping @pcanal

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants