Skip to content

Optimize Keyword.pop/3, pop!/2, and pop_lazy/3#15466

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
preciz:optimize-keyword-pop
Jun 12, 2026
Merged

Optimize Keyword.pop/3, pop!/2, and pop_lazy/3#15466
josevalim merged 1 commit into
elixir-lang:mainfrom
preciz:optimize-keyword-pop

Conversation

@preciz

@preciz preciz commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

Eliminate redundant list traversal by calling :lists.keyfind + delete_key
directly instead of going through fetch/2 + delete/2.

The old code performed 3 traversals when the key was present:

  1. :lists.keyfind (inside fetch)
  2. :lists.keymember (inside delete — redundant)
  3. delete_key (inside delete)

The new code performs 2 traversals:

  1. :lists.keyfind (find the value)
  2. delete_key (remove all matching entries)

Benchmark shows ~1.15x speedup on avg (noisy system)

Because I have read the CONTRIBUTING.md AI section just now:
Assisted-by: Antigravity CLI : Claude Opus 4.6 & Gemini Flash 3.5

Eliminate redundant list traversal by calling :lists.keyfind + delete_key
directly instead of going through fetch/2 + delete/2.

The old code performed 3 traversals when the key was present:
1. :lists.keyfind (inside fetch)
2. :lists.keymember (inside delete — redundant)
3. delete_key (inside delete)

The new code performs 2 traversals:
1. :lists.keyfind (find the value)
2. delete_key (remove all matching entries)

Benchmark shows ~1.15x speedup on avg (noisy system)
@josevalim josevalim merged commit b48221d into elixir-lang:main Jun 12, 2026
15 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

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