[SERVER-54289] Use std::to_chars in DecimalCounter Created: 04/Feb/21  Updated: 14/Dec/22

Status: Backlog
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: None

Type: Improvement Priority: Minor - P4
Reporter: Gregory Noma Assignee: Backlog - Storage Execution Team
Resolution: Unresolved Votes: 0
Labels: neweng
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-62994 Upgrade server build from v3 toolchai... Closed
Related
related to SERVER-54106 Make DecimalCounter able to be constr... Closed
Assigned Teams:
Storage Execution
Participants:

 Description   

When constructing a DecimalCounter starting at a nonzero value, currently we use our custom ItoA to parse the number into a string. It may be a bit cleaner to instead use std::to_chars.

In SERVER-54106, we were unable to use std::to_chars due to the lack of a definition for std::__1::__itoa::__u32toa in Xcode 10, which we use for our macOS builds. Once we upgrade to Xcode 11, we may be able to use std::to_chars.

DecimalCounter<T>(T start = 0)
    : _lastDigitIndex(
          start ? std::to_chars(_digits, _digits + kBufSize, start).ptr - _digits - 1 : 0),
      _counter(start) {}



 Comments   
Comment by Alex Neben [ 14/Dec/22 ]

FYI: v4 toolchain just merged so this should be unblocked.

Comment by Gregory Noma [ 02/Sep/22 ]

std::to_chars should be fast; part of the work here is to compare its performance with the current implementation. There is already a microbenchmark for this.

Comment by Geert Bosch [ 02/Sep/22 ]

What is the point of this change? It's only a single-time memcpy, which should be fine for perf. Typically any standard library string formatting is very slow.

Generated at Thu Feb 08 05:33:07 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.