GObject type system: slow?
GObject type system: slow?
Posted Aug 20, 2025 8:55 UTC (Wed) by linuxrocks123 (subscriber, #34648)In reply to: GObject type system: slow? by mathstuf
Parent article: Hashimoto: We rewrote the Ghostty GTK application
strlen is supposted to constexpr for string literals, so what you said didn't make sense to me. I tried it out on my machine just now to make sure:
---
#include <string>
using namespace std;
bool is_elf_friend(string x)
{
return x=="mellon";
}
---
This compiles to:
---
_Z13is_elf_friendNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE:
.LFB1425:
.cfi_startproc
xorl %eax, %eax
cmpq $6, 8(%rdi)
je .L7
ret
.p2align 4,,10
.p2align 3
.L7:
movq (%rdi), %rax
cmpl $1819043181, (%rax)
je .L8
.L3:
movl $1, %eax
.L4:
testl %eax, %eax
sete %al
ret
.p2align 4,,10
.p2align 3
.L8:
cmpw $28271, 4(%rax)
jne .L3
xorl %eax, %eax
jmp .L4
.cfi_endproc
---
That cmpq $6 instruction is doing an obvious immediate comparison based on the length of "mellon", followed by an early return if the length of the parameter does not match. So, I don't think you're correct.
Posted Aug 21, 2025 13:45 UTC (Thu)
by mathstuf (subscriber, #69389)
[Link]
Even without that, the different connotations implied at the API boundaries are still useful regardless IMO.
GObject type system: slow?