Skip to content

Repeated require/freshRequire leak memory and prevent effective just-in-time compilation #145

Description

@smarr

This is more an attempt to document the issue (there's a change here that others might want to try though: smarr@66b8e9b).

I assume ChartjsNodeCanvas is designed to ensure perfect isolation of plugins, and supporting all kind of Chart.js plugins. To achieve this, I assume, the idea was to just require plugins and other code separately to ensure complete isolation.

However, this also leads to high memory overhead and additional costs such as requiring extra compilation by Node.js for every single canvas. So, creating a canvas is prohibitively expensive, perhaps more so that the documentation suggests already. The other problem is that requiring large chunks of code again and again leaks memory for the code, and then for the native compilation. Node.js doesn't really like this.

In my fork, I stripped out all require()/freshRequire() calls since I don't need the support for legacy plugins and plugin isolation. So, that's not something I can generally recommend. However, it comes at major performance gains of cutting chart render time by 50-80% in my case.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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