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

Remove LEVELS() accessor #1726

Open
lionel- opened this issue Jul 2, 2024 · 1 comment · May be fixed by #1728
Open

Remove LEVELS() accessor #1726

lionel- opened this issue Jul 2, 2024 · 1 comment · May be fixed by #1728

Comments

@lionel-
Copy link
Member

lionel- commented Jul 2, 2024

Part of #1706

LEVELS() was added in #1187

Used to detect non-utf8 strings in r_obj_encode_utf8() and optimise the default case of no encoding conversion needed:

  • Avoid cloning a STRSXP if no translation is needed.
  • Avoid allocating a CHARSXP if no translation is needed (in case of mixed encodings in the vector, less important I guess?).

We could just call Encoding(x) <- "UTF8" from R. This will unconditionally clone the input vector unless it doesn't have any references. To preserve our optimisation, either of these would work:

  • Add a predicate to the C API to determine if a CHARSXP is encoded in UTF8

  • Improve do_setencoding() to only duplicate if needed so that it's a noop in the common case. Bonus points if exported on C side, e.g. as Rf_EnsureUtf8()?

My sense is that these new unconditional allocs would be bad for performance in dplyr. @DavisVaughan you added these optimisations for vctrs, could you confirm please?

@lionel-
Copy link
Member Author

lionel- commented Jul 2, 2024

There's now wch/r-source@0c753e4 so we should be able to preserve our optimisations.

lionel- added a commit that referenced this issue Jul 2, 2024
@lionel- lionel- linked a pull request Jul 2, 2024 that will close this issue
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

Successfully merging a pull request may close this issue.

1 participant