[Optimization] Switch to std::string_view in locations where std::string was utilized #26

Closed
opened 1 year ago by sigonasr2 · 3 comments
Owner

std::string_view is much more efficient when it comes to string handling and should be used in place of std::string wherever possible to prevent heavy copying. Caching WrapText calls to reduce the overhead on text parsing when it comes to displaying text by having a wrapped version of each label stored in memory and utilizing that instead of calculating and manipulating the string every frame on-the-fly.

`std::string_view` is much more efficient when it comes to string handling and should be used in place of `std::string` wherever possible to prevent heavy copying. Caching `WrapText` calls to reduce the overhead on text parsing when it comes to displaying text by having a wrapped version of each label stored in memory and utilizing that instead of calculating and manipulating the string every frame on-the-fly.
sigonasr2 added the
major
enhancement
labels 1 year ago
sigonasr2 self-assigned this 1 year ago
Poster
Owner

The current WrapText implementation assumes we want to modify the string. But thinking about what wrapping text does internally, we update a position marker and when we reach a point beyond the desired width, we move the position marker down and back over. This can all be accomplished with a string view and doesn't actually need a string copy operation, or multiple for that matter, which are very very expensive.

Do this inside the current draw text functions with a wrap text flag and we get wrapping text almost for free.

The current `WrapText` implementation assumes we want to modify the string. But thinking about what wrapping text does internally, we update a position marker and when we reach a point beyond the desired width, we move the position marker down and back over. This can all be accomplished with a string view and doesn't actually need a string copy operation, or multiple for that matter, which are very very expensive. Do this inside the current draw text functions with a wrap text flag and we get wrapping text almost for free.
Poster
Owner

Commit d29f7d47bd addresses the WrapText implementation and has incorporated the wrapping completely within the DrawString and GetTextSize functions.

As those are our only use cases for text wrapping, this is ideal.

Commit http://sig.projectdivar.com/sigonasr2/Crawler/commit/d29f7d47bd614b0701cbb63d020b59de04c25d9e addresses the WrapText implementation and has incorporated the wrapping completely within the `DrawString` and `GetTextSize` functions. As those are our only use cases for text wrapping, this is ideal.
Poster
Owner

Completed in commit
5d1e0b5a7a

Completed in commit http://sig.projectdivar.com/sigonasr2/Crawler/commit/5d1e0b5a7ad7efbb01029a8fd2882df0dad88740
sigonasr2 closed this issue 1 year ago
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date

No due date set.

Dependencies

No dependencies set.

Reference: sigonasr2/AdventuresInLestoria#26
Loading…
There is no content yet.