Skip to content

potentially accelerate trace/symbol recovery by reusing buffers #738

@workingjubilee

Description

@workingjubilee

There is a potential issue in do_resolve, where we rebuild the return-value buffer each time on the stack:

unsafe fn do_resolve(
sym_from_addr: impl FnOnce(*mut SYMBOL_INFOW) -> BOOL,
get_line_from_addr: impl FnOnce(&mut IMAGEHLP_LINEW64) -> BOOL,
cb: &mut dyn FnMut(&super::Symbol),
) {
const SIZE: usize = 2 * MAX_SYM_NAME as usize + mem::size_of::<SYMBOL_INFOW>();
let mut data = Aligned8([0u8; SIZE]);
let info = unsafe { &mut *data.0.as_mut_ptr().cast::<SYMBOL_INFOW>() };
info.MaxNameLen = MAX_SYM_NAME as u32;
// the struct size in C. the value is different to
// `size_of::<SYMBOL_INFOW>() - MAX_SYM_NAME + 1` (== 81)
// due to struct alignment.
info.SizeOfStruct = 88;

This sort of thing might happen elsewhere in the code, too.

We're not expected to be the fastest thing but if we find free performance lying on the floor, well, why not?

Noted in #737 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions