Macaulay2 / Macaulay2/M2

Optimizing overhead of syntactic sweeteners for functions

Open
#4,230 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Interpreter
Dominant language
Macaulay2
Stars
435
Forks
297
Avg merge
4d 20h
Merged PRs (30d)
11

Description

I have a question that I don't know how to best evaluate: between the following, which one is more computationally efficient?

apply(L, y -> blah(x, y))
apply(L, blah_x)

How about the following:

apply(L, x -> not blah x)
apply(L, not blah)

Or how about:

apply(L, x -> blah foo x)
apply(L, blah @@ foo)

My vague intuition is that the first choice is more efficient, because it has expanded one layer of the function comprehension. However, at least the pseudocode for the latter choice is shorter in all cases (I know shorter pseudocode doesn't necessarily mean more efficient, but I'm not exactly sure how smart the interpreter is). For instance:

i1 : pseudocode(() -> apply(L, y -> blah(x, y)))

o1 = function restargs false
              numparms 0
              framesize 0
              frameID 9065
              body adjacent global-fetch 404
                            sequence global-fetch 3438
                                     function restargs true
                                              numparms 1
                                              framesize 1
                                              frameID 9066
                                              body adjacent global-fetch 3439
                                                            sequence global-fetch 3440
                                                                     local-fetch 0 0

o1 : PseudocodeClosure

i2 : pseudocode(() -> apply(L, blah_x))

o2 = function restargs false
              numparms 0
              framesize 0
              frameID 9067
              body adjacent global-fetch 404
                            sequence global-fetch 3438
                                     2-OP _ global-fetch 3439
                                            global-fetch 3440

o2 : PseudocodeClosure

The answer ultimately probably depends on what optimizations the interpreter performs, which is really what this question is all about.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the three function-comparison examples and their pseudocode output, then investigate how the interpreter evaluates function comprehensions and the shorter syntactic forms. Benchmark the alternatives and inspect the generated pseudocode; done means the relative overhead and any applicable interpreter optimizations are established and documented.

Written by the indexing model from the issue text.

Assessment

Domain
compilers, performance
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.