Skip to content

Conversation

@ike709
Copy link
Collaborator

@ike709 ike709 commented Oct 28, 2024

Changed the peephole optimizer to support arbitrary passes over the bytecode with different optimizations instead of trying (and failing) to do everything in one go, as opts like PushNFloats would break the GetOpcodes() checks of other optimizations.

IPeepholeOptimization has been renamed to IOptimization. Individual optimizer passes are the inheritor interfaces of this parent interface.

Here are the passes in order:

  1. IPeepholeOptimization - Runs pretty much everything not involving PushN opcodes
  2. IBytecodeCompactor - Converts multiple Push opcodes to PushN opcodes
  3. IListCompactor - Converts PushN... CreateList to CreateListN... opcodes

I ran my usual bytecode analysis scripts on TG and confirmed that we're now running const folding optimizations (in the first pass) 100% of the time. I also confirmed that second-pass and third-pass optimizations are also being applied.

I booted TG and confirmed it doesn't explode. I also ran the profiler and confirmed that the performance impact is negligible:
image

Closes #2059

@boring-cyborg boring-cyborg bot added the Compiler Involves the OpenDream compiler label Oct 28, 2024
@ike709 ike709 requested a review from wixoaGit October 28, 2024 19:40
@github-actions
Copy link

github-actions bot commented Nov 3, 2024

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@wixoaGit
Copy link
Member

wixoaGit commented Nov 3, 2024

Instead of having the different interfaces for each pass, could we instead have a property that describes which pass each optimization is applied on? You could have a static const or enum to keep the naming of each pass. Like:

public int OptPass => IOptimization.PassListCompaction;

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@github-actions
Copy link

This pull request has conflicts, please resolve those before we can evaluate the pull request.

@ike709 ike709 requested a review from wixoaGit November 17, 2024 18:41
@wixoaGit wixoaGit merged commit 12b9f6e into OpenDreamProject:master Nov 21, 2024
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Compiler Involves the OpenDream compiler size/XL

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PushN peephole opts need a separate pass

2 participants