Skip to content

Avoid quadratic behavior when cleaning assembly labels - #1284

Merged
shepmaster merged 3 commits into
mainfrom
quad-graph
Oct 14, 2026
Merged

shepmaster merged 3 commits into
mainfrom
quad-graph

Conversation

@shepmaster

Copy link
Copy Markdown
Member

No description provided.

If you had a tree of labels like this:

```
  mov .L0
  mov .L1
  mov .L2
.L0:
  .quad .L1
.L1:
  .quad .L2
.L2:
  .quad 1
```

The graph processing would take quadratic time because it started at
each label referenced by the initial instructions and walk the entire
graph over and over, repeating nodes. We now avoid re-visiting the
same node.

| # of labels | original time (ms) | improved time (ms) |
|------------:|-------------------:|-------------------:|
|        1000 |               37.7 |                4.2 |
|        2000 |              132.9 |                4.9 |
|        4000 |              538.1 |                5.7 |
|        8000 |             2394.2 |               13.1 |

I don't know how feasible it is to write realistic Rust code that
generates this assembly. I think you'd have to have a bunch of
`static`s that reference each other and then use all of them.

Regardless, this is a small change to address the possibility.
@shepmaster shepmaster added the maintenance Keeping the wheels turning label Oct 14, 2026
@shepmaster
shepmaster merged commit 9f5b8a8 into main Oct 14, 2026
9 checks passed
@shepmaster
shepmaster deleted the quad-graph branch October 14, 2026 19:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance Keeping the wheels turning

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant