Skip to content

perf: check the allow list before disposable? in disposable_with_allow_list - #331

Open
mebezac wants to merge 1 commit into
micke:mainfrom
mebezac:perf/allow-list-before-disposable
Open

mebezac wants to merge 1 commit into
micke:mainfrom
mebezac:perf/allow-list-before-disposable

Conversation

@mebezac

@mebezac mebezac commented Nov 3, 2026

Copy link
Copy Markdown

The problem

The check is address.disposable? && !address.allow_listed?.
disposable? also checks the MX servers, so it does a DNS lookup.
Because disposable? runs first, every address does this lookup. This includes allow-listed domains, for example gmail.com.

Why the order matters

Ruby stops an && check when the first part is false.
If we check the allow list first, allow-listed addresses stop there. They do not get to the DNS lookup.

The change

Swap the order: !address.allow_listed? && address.disposable?

…w_list

disposable? also checks the MX servers, so it does a DNS lookup. It ran
before allow_listed?, so every address did the DNS lookup, also when
the domain was on the allow list (for example gmail.com). Check
allow_listed? first. Allow-listed addresses now skip the DNS lookup.
The result does not change.
@phoet

phoet commented Nov 5, 2026

Copy link
Copy Markdown
Collaborator

This is reasonable

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.

2 participants