Skip to content

perf: Pass logging arguments as const-ref to prevent repetitive copying - #278

Merged
hsluoyz merged 1 commit into
apache:masterfrom
cbaecker:perf/pass-logging-const-ref
Oct 31, 2026
Merged

hsluoyz merged 1 commit into
apache:masterfrom
cbaecker:perf/pass-logging-const-ref

Conversation

@cbaecker

@cbaecker cbaecker commented Oct 30, 2026 •

Copy link
Copy Markdown
Contributor

Slight improvement to logger. Pass arguments as const-ref to prevent copying.

Enforcer calls LogPrint() in various locations, e.g. in the loop iterating the policy. This creates a copy every time.

for (auto& p_vals : p_policy ) {
casbin::LogUtil::LogPrint("Policy Rule: ", p_vals);

LogPrint() itself passes arguments to an instance of DefaultLogger, which takes another copy.

void Print(std::string format, Object... objects) {

Internal logger is a no-op and copy elision may help, but i was still able to measure slight performance improvement.
Copies should be avoided unless required, e.g. for asynchronous processing.

This may affect existing implementations of the abstract Logger-class.

@hsluoyz
hsluoyz merged commit 78b5968 into apache:master Oct 31, 2026
7 checks passed
@cbaecker
cbaecker deleted the perf/pass-logging-const-ref branch October 31, 2026 07:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants