perf: introduce CFReleaseThread for running CoreFoundation releases

Some CoreFoundation objects, such as those produced by CoreText, have
expensive callbacks that run when they are released. By offloading the
CFRelease calls to another thread, we can avoid important threads being
blocked by unexpectedly expensive callbacks.

This commit also changes the way that the coretext shaper's run iterator
builds its string. Rather than using a CFMutableString, an ArrayList of
unichars is built which is passed to CFStringCreateWithCharactersNoCopy,
which is a lot more efficient since it avoids all the CoreFoundation
overhead.
This commit is contained in:
Qwerasd
2024-06-14 01:43:02 -04:00
parent 04896a14b4
commit 626ec2b5ac
4 changed files with 307 additions and 25 deletions

View File

@@ -19,6 +19,17 @@ pub const String = opaque {
)))) orelse Allocator.Error.OutOfMemory;
}
pub fn createWithCharactersNoCopy(
unichars: []const u16,
) *String {
return @as(*String, @ptrFromInt(@intFromPtr(c.CFStringCreateWithCharactersNoCopy(
null,
@ptrCast(unichars.ptr),
@intCast(unichars.len),
foundation.c.kCFAllocatorNull,
))));
}
pub fn release(self: *String) void {
c.CFRelease(self);
}