Skip to content

Tuple operations performance boost + fix logic bug#15376

Merged
josevalim merged 3 commits into
elixir-lang:mainfrom
gldubc:tuple-operations-performance
May 14, 2026
Merged

Tuple operations performance boost + fix logic bug#15376
josevalim merged 3 commits into
elixir-lang:mainfrom
gldubc:tuple-operations-performance

Conversation

@gldubc
Copy link
Copy Markdown
Member

@gldubc gldubc commented May 14, 2026

Logic bug

Fixes a few tuple operation edge cases around negative tuple constraints. For example:

difference(tuple(), empty_tuple())
|> tuple_insert_at(1, boolean())

This is “all non-empty tuples”, so inserting at index 1 should work and produce open_tuple([term(), boolean()])

This also fixes the dynamic side of tuple operations, e.g. tuple_delete_at(dynamic(tuple([integer(), atom()])), 2) now correctly returns :badindex instead of building an empty dynamic result.

Performance boost

Finally, we apply the same projection shortcut we added for map operations: when working with projected negative constraints, avoid fully expanding the negative split if we can prove one projected side survives unchanged.

This makes projected-negative tuple operations faster on large types (for N=500 differences, on local benchmarks, we go from 8s for fetch to 100ms, and 600ms for insert ops to 50ms).

@josevalim josevalim merged commit 71148aa into elixir-lang:main May 14, 2026
15 checks passed
@josevalim
Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

@josevalim josevalim deleted the tuple-operations-performance branch May 14, 2026 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants