Skip to content

Conversation

@tisonkun
Copy link
Contributor

This follows up #673 (review).

cc @EFanZh not sure if it creates some overhead or how can I check it.

Signed-off-by: tison <wander4096@gmail.com>
target_module_path_and_loc,
kvs.into_kvs(),
)
fn do_log<'a>(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we’re going to do it this way these names should probably be much more mangled, like __log_private_api_log. Similarly, the name of the trait should also be ugly so it doesn’t look like something you’re meant to use directly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree. I'd first check whether this way work (so that all the zero-size logger can benefit). And rename later.

$logger,
use $crate::__private_api::LogExt;

$logger.do_log(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You may need to refer to the trait directly: LogExt::do_log(...), otherwise if the logger has a do_log method that is not a trait method, it will be called here.

kvs.into_kvs(),
)
fn do_log<'a>(
&self,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forces caller to pass a non-ZST reference, which causes the ZST optimization to lose effect.

Copy link
Contributor Author

@tisonkun tisonkun Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see that the final fn log(&self, ..) and fn enabled(&self, ..) method take a reference also.

So the optimization happens only in the caller-side if we take the ownership, as you described in #576 (comment)?

Copy link
Contributor

@EFanZh EFanZh Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. You need to make sure that the arguments passed to the outermost function are ZSTs. That’s why the original generic wrapper function exists.

Copy link
Contributor Author

@tisonkun tisonkun Mar 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Then I'd close this PR as not work.

Although, I wonder if write! use $dst.write_fmt that accepts a reference already, is the ZST optimization significant? Or a net win?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The binary size reduction depends on the number of log macro calls, it may have different impact on different projects. I remember seeing observable binary size reduction in one of my projects with a lot of logs with this optimization.

@tisonkun tisonkun closed this Mar 24, 2025
@tisonkun tisonkun deleted the logext branch March 24, 2025 07:15
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.

3 participants