Giter Club home page Giter Club logo

Comments (2)

ChALkeR avatar ChALkeR commented on July 4, 2024

Almost all of this comes from the way you are building the result string, context_data_string += … lines.

Replacing context_data_string with an Array and doing push/join('') decreases 900M to 80M.
You could also preallocate the Array of some fixed length (depending on the input length) and manually use [i++] on that. I haven't measured which of those the variants (string, Array.prototype.push, preallocated Array) is faster.

from lz-string.

ChALkeR avatar ChALkeR commented on July 4, 2024

Ok, here are the test results with iojs:

50000 iterations, String concat (current): 31 seconds, 905 MiB.
50000 iterations, Array push/join: 29 seconds, 81 MiB.
50000 iterations, Array prealloc/[i++]/join: 32 seconds, 81 MiB.
50000 iterations, Array push/join + ES6: 15 seconds, 79 MiB.

100000 iterations, String concat (current): 1212 seconds, 1760 MiB, the gc kicked in,
100000 iterations, Array push/join: 57 seconds, 114 MiB.
100000 iterations, Array prealloc/[i++]/join: 69 seconds, 115 MiB.
50000 iterations, Array push/join + ES6: 30 seconds, 107 MiB.

200000 iterations, String concat (current): I terminated it after 100 minutes, 2450 MiB, the gc kicked in,
200000 iterations, Array push/join: 120 seconds, 172 MiB.
200000 iterations, Array prealloc/[i++]/join: 139 seconds, 172 MiB.
50000 iterations, Array push/join + ES6: 61 seconds, 164 MiB.

There is enough free memory and swap is disabled, so it didn't affect the results.

from lz-string.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.