Skip to content

Function inlining #362

@WeiseSchokolade

Description

@WeiseSchokolade

Related problem or need

Inlining functions would fix optimization issues such as:

  • Calling single-line functions that are necessary because they're used in multiple places but make a single call count as two commands.
  • Calling multiline-functions without using /execute or something similar. Happened to me multiple times when using external libraries and such.
  • Calling functions with an AOT-known macro: Leads to minecraft having to compile a macro even though it doesn't change

Proposed solution

Inlining functions:
If the called function only contains a single command, replace calls of that function with the contained command.
If the context of the function isn't changed, just replace the call of the function with the function's content.
Inlining macro-function-calls is probably a bit more difficult, because that would require a separate string-nbt parser. It would definitely pay off though!

Presumably, it'd always be necessary to leave the original function in place because it's usually unclear whether a function of a different datapack is still depending on it.

Properly figuring out the places where a function is called would probably lead to another few optimization. For one, since multiline commands exist nowadays, it would probably be necessary to turn those into single-line commands. That would have the side effect of getting rid of unnecessary characters. In addition to that, if one's already tempering with the content of functions, removing comments and blank lines would also be a possible optimization.

Alternative solutions

Can't think of any. :/

Additional context

Might be a helpful resource: https://en.wikipedia.org/wiki/Inline_expansion

A while ago, before I knew about this project, I tried something similar myself. Never got close to where you are! Keep up the good work!

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions