Skip to content

Merge compiler flags in linear time - #52

Open
OskarEichler wants to merge 2 commits into
ruby-gnome:mainfrom
OskarEichler:codex/linear-cflag-merge
Open

Merge compiler flags in linear time#52
OskarEichler wants to merge 2 commits into
ruby-gnome:mainfrom
OskarEichler:codex/linear-cflag-merge

Conversation

@OskarEichler

Copy link
Copy Markdown

Summary

Retain the last occurrence of mergeable -D/-W flags using a reverse traversal and a seen set; preserve all nonmergeable flags and their order.

Reproduction and verification

The previous Array#delete on each mergeable flag repeatedly scans the output. A 1,000-distinct-flag input takes quadratic work. The candidate visits each input once and reverses the result once. A fixed-seed corpus of 1,000 mixed arrays matches the original algorithm exactly, including -Wa/-Wl/-Wp exceptions and frozen input arrays.

Paired Ruby 4.0.6 benchmark: 12 rounds, two warmups. For 100 merges of 1,000 distinct flags: median 0.250664s -> 0.014598s; repeated flags: 0.136190s -> 0.010624s. For 20,000 six-flag merges: 0.020347s -> 0.020816s, with one extra hash allocation per call. No universal speedup or production-throughput claim.

Existing suite on Ruby 4.0.6 through rbenv: 27 tests, 31 assertions, zero failures/errors, two upstream macOS omissions, baseline and this isolated patch. Combined installed-release consumer also passes the suite, 1,098 focused/model checks, four process cases, five linker-option cases and four path cases. rbenv exec ruby test/run.rb runs the existing suite.

Compatibility and limitations

No output/API change intended. Tradeoff: a seen hash and tiny measured small-input overhead in exchange for linear scaling.

No tests were added or modified under the consuming repository's no-new-tests policy. Verification uses existing tests and external scratch reproductions. No production changes; older Ruby/Linux/Windows matrices await upstream CI. No unrelated version/dependency changes.

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