Skip to content

Perf impact on module load seems to be depending on the number of hooks defined.  #83

@pgayvallet

Description

@pgayvallet

During our investigations trying to optimize Kibana's startup time, we discovered that the perf impact of using require-in-the-middle was depending on the number of Hook that were defined. (More details in elastic/kibana#178285, but we're talking about ~20% performance gain in total module load time by using only one hook instead of 5)

The implementation of RITM seems to confirm it, given each instance of Hook is patching Module.prototype.require, therefor patching the already-patched require from the previous Hook.

I would expect the library to perform the patching only once, and handle all the registered hooks from this single patched method. It would avoid the interception logic to be executed each time for each hook, for each import.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions