Skip to content

Using getfenv to get requiring script Name disables Luau optimization #5

@Ozzypig

Description

@Ozzypig

The use of any of these functions [loadstring, getfenv, setfenv] performs a dynamic deoptimization, marking the affected environment as “impure”. The optimizations are only in effect on functions with “pure” environments - because of this, the use of loadstring/getfenv/setfenv is not recommended. Note that getfenv deoptimizes the environment even if it’s only used to read values from the environment.

https://roblox.github.io/luau/performance.html#importing-global-access-chains

Modules currently gets the requiring script's name using getfenv, as this paragraph describes. This disables Luau optimizations, as the requiring script's environment becomes "impure".

A suggestion made by @howmanysmall provides a good alternative: using debug.traceback to create the "require taking too long" warnings. The output format of debug.traceback is not defined, so parsing its output is a bad idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions