Skip to content

remove unnecessary memory allocation from ConcatSource and ReplaceSource #30

Closed

Description

@MagicDuck

The code in ConcatSource::source() and ReplaceSource::_replaceString() is using array.join("") which causes allocation of new strings. Using simple concatenation with += instead causes node to create what it calls something like "concatenated strings" internally which reuse the memory of the original strings being concatenated (this is probably possible since strings are immutable).

This problem was discovered by recording a "memory allocation profile" using chrome dev tools for the duration of the whole webpack build.

Before:
image

After change:
image

Activity

  1. MagicDuck commented on Nov 24, 2017

    @MagicDuck
    ContributorAuthor

    I will create a PR soon.

  2. filipesilva commented on Nov 25, 2017

    @filipesilva

    Think this can be closed since #31 was merged.

  3. joshwiens commented on Nov 25, 2017

    @joshwiens

    Thanks @MagicDuck

  4. MagicDuck commented on Nov 25, 2017

    @MagicDuck
    ContributorAuthor

    No worries :)
    There's a bunch more, on a more minor level, that i have seen in the source-list-map project. I want to see what can be done. The most bizarre one is this: https://github.com/webpack/source-list-map/blob/master/lib/helpers.js
    I am not sure why dev tools is reporting getNumberOfLines as allocating tens of mb in my case...

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

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions