Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSE Machine: Avoid pushing unnecessary env instructions #1687

Merged
merged 4 commits into from
Apr 23, 2024

Conversation

DiligentPenguinn
Copy link
Contributor

Description

This PR implements simple logic to avoid pushing envInstr when not needed. Specifically, envInstr can be avoided if there are no environment-dependent commands on the control. A command is environment-dependent if its evaluation depends on the context given by the current environment.
Implements and resolves #1682

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Code quality improvements

How to test

The following programs should run with no environment instructions being pushed

@DiligentPenguinn DiligentPenguinn added the Enhancement New feature or request label Apr 22, 2024
@DiligentPenguinn DiligentPenguinn self-assigned this Apr 22, 2024
@coveralls
Copy link

Pull Request Test Coverage Report for Build 8786106267

Details

  • 22 of 23 (95.65%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage increased (+0.03%) to 82.096%

Changes Missing Coverage Covered Lines Changed/Added Lines %
src/cse-machine/utils.ts 20 21 95.24%
Totals Coverage Status
Change from base Build 8700098795: 0.03%
Covered Lines: 10917
Relevant Lines: 12952

💛 - Coveralls

Copy link
Member

@martin-henz martin-henz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a safe strategy to avoid unnecessary env instructions. It could be further generalized, but this is good enough for now. The advantage is that it is easy to do: doesn't complicate the machine very much.

@martin-henz martin-henz merged commit 60d3de2 into master Apr 23, 2024
4 checks passed
@martin-henz martin-henz deleted the cse-machine-simplify-env-instr branch April 23, 2024 01:58
@DiligentPenguinn
Copy link
Contributor Author

@martin-henz yes, I was thinking that further generalization would add extra complication to what is a pedagogical strategy. If this is desired then I can further work on it in the future to be more exhaustive.

@martin-henz
Copy link
Member

The canAvoidInstr function is extremely inefficient and slows down the deployment each time by almost one hour! @RichDom2185 and @sayomaki commented:

the code is not very efficient at all, it seems; we can just early return instead of iterating through the entire control every single step of the cse machine

I'm pretty sure this alone accounts for most of the 40minutes

same thing for the switch case logic, lots of unnecessary computation

@sayomaki :
consider using javascript's Array.some() or Array.every() instead

@RichDom2185 :
yes that also works, no need for a for loop, though I think the logic can be improved further

because the same computation is being repeated at every step

it should have been memoised

just create a new field in the control item and calculate it once only instead of calculating n times for each item where n is the number of control items

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement New feature or request
Projects
Development

Successfully merging this pull request may close these issues.

CSE: Avoid unnecessary env instructions
3 participants