Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide ShortByteString API #225

Open
hasufell opened this issue Jan 19, 2024 · 2 comments
Open

Provide ShortByteString API #225

hasufell opened this issue Jan 19, 2024 · 2 comments

Comments

@hasufell
Copy link
Member

hasufell commented Jan 19, 2024

ShortByteString now has the same API as ByteString. It has certain benefits and is used in the new OsPath type.

@hasufell
Copy link
Member Author

hasufell commented Jan 22, 2024

I guess most of the optimization tricks rely on the fact that we can walk and shift around buffers in ByteString and Text without copying any data (which is not true for ShortByteString).

So a ShortByteString API would likely just do fromShort and toShort at the outer layers? I could attempt a full ShortByteString implementation, but my guess is that it would be magnitudes slower due to more copying.

@hasufell
Copy link
Member Author

After writing my blog The ultimate guide to Haskell Strings I think the most sensible strategy is to:

  • provide a Bytes API from the byteslice package
    • these can be pinned or unpinned
    • conversion from ShortByteString is O(1)
    • they can slice as efficiently as Text or ByteString
  • then ShortByteString users can convert to Bytes and run the parser
  • we also get ShortText support for free (conversion to Bytes is O(1) too)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant