Suboptimal code generation for string literal logs #365

Closed
opened 2019-11-19 13:57:34 -06:00 by sfackler · 2 comments
sfackler commented 2019-11-19 13:57:34 -06:00 (Migrated from github.com)

#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

#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: ```rust use log::info; fn main() { info!("hello world"); } ``` ```asm 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
sfackler commented 2019-11-19 13:57:41 -06:00 (Migrated from github.com)

cc @Amanieu

cc @Amanieu
sfackler commented 2019-11-19 14:20:22 -06:00 (Migrated from github.com)

I may have misread this - the thing being assembled on the stack is actually the Arguments struct, not the tuple.

It seems like we may want a separate function when the argument's just a string literal.

I may have misread this - the thing being assembled on the stack is actually the Arguments struct, not the tuple. It seems like we may want a separate function when the argument's just a string literal.
Sign in to join this conversation.
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gh-rust-lang/log#365
No description provided.