Skip to content

perf: Is caching the token string worth it if we have to spend an operation clearing the string on setting every start/end position. #179

@SharafMohamed

Description

@SharafMohamed

Request

In the Token class we always cache the string in to_string and also cache the string in to_string_view if it is the wrap around case for the circular buffer. However, the cost of maintaining this cached string is a string reset call when setting the token start/end positions. There are two cases to consider:

  1. The Token string is accessed several times, in which case rebuilding it is expensive. However, the caller could just cache it themselves if this was the case.

  2. The token string is accessed once, in which case there is no point to cache the string.

Also, in both cases, the wrap around case should happen so infrequently its not worth caching it.

Possible implementation

Remove the cached string and always compute the string if to_string or to_string_view is called.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions