Skip to content

[SR-447] Parsing strings into floating-point performs badly #43064

Closed
@lilyball

Description

@lilyball
Previous ID SR-447
Radar rdar://problem/23114536
Original Reporter @lilyball
Type Bug
Additional Detail from JIRA
Votes 0
Component/s Standard Library
Labels Bug, Performance
Assignee None
Priority Medium

md5: 9c2a4c230f784781f1a8d22b417b5029

relates to:

Issue Description:

The implementations of init?(_ text: String) for the various floating-point formats relies on calling strtod_l (or the appropriate variant thereof). This requires calling String.withCString, which makes a copy of the string (so it can add the NUL terminator). This means that every single parse of a floating-point number incurs an allocation and copy, which can be prohibitively expensive in a tight loop.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DoubleArea → standard library: The `Double` typeStringArea → standard library: The `String` typebugA deviation from expected or documented behavior. Also: expected but undesirable behavior.performancestandard libraryArea: Standard library umbrella

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions