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

CodePoints.uncons performance optimization? #154

Open
jamesdbrock opened this issue Sep 23, 2021 · 3 comments
Open

CodePoints.uncons performance optimization? #154

jamesdbrock opened this issue Sep 23, 2021 · 3 comments
Labels
type: enhancement A new feature or addition.

Comments

@jamesdbrock
Copy link

It seems to me that these lines in Data.String.CodePoints.uncons

cu0 = fromEnum (Unsafe.charAt 0 s)
cu1 = fromEnum (Unsafe.charAt 1 s)

are first slicing the first code unit into a Char string with the JavaScript charAt method

if (i >= 0 && i < s.length) return s.charAt(i);

and then converting the Char string to a CodePoint by the boundedEnumChar instance fromEnum method which calls the Javascript charCodeAt method.

https://github.com/purescript/purescript-enums/blob/170d959644eb99e0025f4ab2e38f5f132fd85fa4/src/Data/Enum.js#L4

We could skip the intermediate string slice of the charAt method and call charCodeAt directly.

@JordanMartinez
Copy link
Contributor

Is it doing that because it makes it easier on other backends?

@jamesdbrock
Copy link
Author

Is it doing that because it makes it easier on other backends?

Maybe. That's a good point.

@jamesdbrock
Copy link
Author

I tried swapping in a “fast” CodePoints.uncons function in purescript-parsing and couldn't detect any speedup.

@JordanMartinez JordanMartinez added the type: enhancement A new feature or addition. label Dec 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A new feature or addition.
Projects
None yet
Development

No branches or pull requests

2 participants