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

Optimize std.findSubstr and std.flattenArrays #216

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

JoshRosen
Copy link

@JoshRosen JoshRosen commented Nov 22, 2024

This PR implements small performance optimizations for two built-in functions:

  • std.findSubstr:
    • Skip array allocation in case of no matches. This is a common scenario because findSubstr is often used to implement "string contains" checks.
    • Use ArrayBuilder instead of ArrayBuffer: in this context we only need to append and don't need to update, remove, or inspect the elements that we've written, and for those requirements ArrayBuilder is cheaper to instantiate and cheaper to invoke.
    • Store Val.Num into the array builder rather than storing indices then mapping the result into an output array: this saves an array allocation and iteration.
  • std.flattenArrays:
    • Apply a similar ArrayBuffer -> ArrayBuilder replacement.

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 this pull request may close these issues.

1 participant