Skip to content

[feature] Add fmtlib for faster string formatting #4

@Bobscorn

Description

@Bobscorn

Is your feature request related to a problem? Please describe.
The problem is the speed and convenience of producing formatted strings.
Currently the solution to produce a formatted string is using string concatenating with std::to_string.
For eg. auto desc = "My Position: (" + std::to_string(pos.x) + ", " + std::to_string(pos.y) + ", " + std::to_string(pos.z) + ")";
This is both cumbersome, a little hard to read, and slow (creates 7 + 6 strings just for 1 resulting string).
It also makes it very difficult to specify significant figures or otherwise fine tune number to string conversion.
Currently the only 2 ways I know of how to specify significant figures in using standard equivalents is via sprintf (a C function) or using std::stringstream with std::setprecision, sprintf requires adapter functions while std::stringstream is cumbersome.

Describe the solution you'd like
I propose using fmtlib to ease creation of formatted strings.
This requires bringing fmtlib in as a dependency, and possibly replacing all or some instances of std::to_string with fmtlib equivalents.

Describe alternatives you've considered
2 alternatives considered are writing a wrapper over sprintf to use that for formatted strings, and writing a from-scratch equivalent of formatted strings.
A wrapper over sprintf would work fairly well, would require a set of functions to ensure sprintf works properly in all situations.
However I am inexperienced with writing a performant wrapper over sprintf, so I believe it would lack speed in comparison to fmtlib.
The other alternative of writing an in-house implementation would require a lot of work, and a lot fine tuning to come close to the performance fmtlib claims to offer.

Additional context
Add any other context or screenshots about the feature request here.

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