Skip to content

[JSI] Support non-copy jsi::String constructors #1597

Open
@mrousavy

Description

Problem

Currently, all jsi::String factory methods (e.g. createFromAscii(...)) copy the given std::string/char*. This could cause unnecessary performance hits if the strings are large, or constexpr/statically known at compile-time

Solution

It would be cool to have a constructor/factory method that doesn't copy the given std::string/std::string_view/char*/char[N]/jsi::ArrayBuffer.

This would be beneficial in two situations:

  • For static/constexpr strings that do not change
  • For huge strings (like JSON strings) that are memory-managed elsewhere (aka "unsafely") to be passed to JS directly and synchronously, and then freed later. This avoids large copies in situations where performance could matter.

Additional Context

I don't know how this works internally in the Runtime, but is it even possible for the Hermes/JSC runtime to not have ownership on a string? I'm guessing strings are not represented using the C++ STL internally, so a conversion from std::string will always happen - but what about char*/char[N]?

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