Skip to content

Suboptimal code generation for string literal logs #365

@sfackler

Description

@sfackler

#278 optimized generated logging code size by packaging up all of the probably-static bits of a log directive (the target, module path, file, and line) up into a single pointer-to-tuple, with the idea being that the compiler would just stick that tuple in .rodata and be able to just load a pointer to it when calling __private_api_log.

Unfortunately, it appears that the compiler is no longer lifting that tuple into a static, and it is instead being assembled on the stack:

use log::info;

fn main() {
    info!("hello world");
}
playground::main:
	subq	$56, %rsp
	movq	log::MAX_LOG_LEVEL_FILTER@GOTPCREL(%rip), %rax
	movq	(%rax), %rax
	cmpq	$3, %rax
	jb	.LBB4_2
	leaq	.L__unnamed_2(%rip), %rax
	movq	%rax, 8(%rsp)
	movq	$1, 16(%rsp)
	movq	$0, 24(%rsp)
	movq	$8, 40(%rsp)
	movq	$0, 48(%rsp)
	leaq	.L__unnamed_3(%rip), %rdx
	leaq	8(%rsp), %rdi
	movl	$3, %esi
	callq	*log::__private_api_log@GOTPCREL(%rip)

.LBB4_2:
	addq	$56, %rsp
	retq

main:
	pushq	%rax
	movq	%rsi, %rcx
	movslq	%edi, %rdx
	leaq	playground::main(%rip), %rax
	movq	%rax, (%rsp)
	leaq	.L__unnamed_1(%rip), %rsi
	movq	%rsp, %rdi
	callq	*std::rt::lang_start_internal@GOTPCREL(%rip)
	popq	%rcx
	retq

https://play.rust-lang.org/?version=stable&mode=release&edition=2018&gist=b9384ea3c6f7870c1d8b12df6e33ce99

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions