Skip to content

Implement load-time initialisation #1

@PyPylia

Description

@PyPylia

Currently, maybe_special only utilises compile-time and run-time (specifically upon first run of a function) dispatch initialisation.

Implementing load-time initialisation, such as with LLVM IFUNCs, would allow for the performance impact of initialisation to be moved to load-time, rather than at run-time, which seems like a better option. LLVM IFUNCs specifically have the issue that it seems like it'd need support from rustc itself to work, which doesn't currently exist as far as I'm aware.

Additionally, this may allow for better optimised code, as currently each individual initialisation function must make many calls to the is_*_feature_detected macros, which are currently quite slow for reasons documented in this thread (the detected features are cached by these macros, but LLVM does not seem to always optimise successive relaxed atomic reads, which is needed by maybe_special for fine-grained feature detection). By moving all initialisation to load-time, the initialisation functions could possibly be combined in some way to partially mitigate this issue.

It is also possible to do this via a global initialisation function called at the start of main (although I don't currently know the details of how that'd work), but that introduces its own issues, such as how to deal with situations where the user forgets to call that function. It may also be possible to direct every initialisation function to a global init function, but again that is complicated, and could cause unexpected lag spikes upon the first call of any specialised function.

Finally, all of this is complicated by the fact I wish to maintain support for all architectures and operating systems. I am currently reliant on std_detect for feature detection, which I am okay with, as it seems to be the best supported feature detection crate (and as such any feature detection issues with this crate should be directed there instead), and I do have a fallback for unsupported systems. Adding additional features that would only be beneficial to a limited number of operating systems and architectures is out of scope for what I am currently aiming to implement, but I will happily accept any PR that does this so long as there are no regressions for other systems.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions