GithubHelp home page GithubHelp logo

Comments (9)

mcollina avatar mcollina commented on June 2, 2024

I would not merge any PRs that have any form of performance degradation.

How did you measured the 14MB?

2 * 65536 = 131072 bytes = 128 KB.

Something else should be going on. Maybe we need to allocate a big buffer, and then slice through it.

from mqtt-packet.

kirilknysh avatar kirilknysh commented on June 2, 2024

I just took the existing number.js, added setInterval(() => {}, 9999); (just not to finish the process immediately) and run node number.js. Then I measured memory with just regular top command (MacOS Sierra, 10.12.4, node v6.5.0).

Node process with the original number.js - 22Mb
Node process with patched code - 9Mb

Keep in mind that this is not JS heap but node process itself.

from mqtt-packet.

mcollina avatar mcollina commented on June 2, 2024

@kirilknysh so, how do you think we can make this configurable? Also, we might check if using an array improve things.

from mqtt-packet.

kirilknysh avatar kirilknysh commented on June 2, 2024

I've tested with an array. Regarding memory - no big difference in both: memory usage and performance.

How to make it configurable - not really sure. Unfortunately, I'm not closely familiar with the overall architecture of the mqttjs. From the first sight - the best candidate is connect packet in writeToStream.js (assuming that connect command is always the first in a flow). Then it could be done similar to settings like protocolId, protocolVersion etc.

from mqtt-packet.

mcollina avatar mcollina commented on June 2, 2024

I don't think it's feasible in that way, and I would not like to change the API.

How about we do:

mqttPacket.cacheNumbers = false

which then replaces the current system? We can do that with a getter I think.

Would you like to attempt a PR?

from mqtt-packet.

kirilknysh avatar kirilknysh commented on June 2, 2024

Sure, I'd love to attempt. One thing: how do you expect to get access to mqttPacket.cacheNumbers from writeToStream.js?

from mqtt-packet.

mcollina avatar mcollina commented on June 2, 2024

I think we might call a method in writeToStream and replace it? Be careful to lazy-load numbers.js only when needed.

from mqtt-packet.

kirilknysh avatar kirilknysh commented on June 2, 2024

How about API like:

var mqttPacket = require('mqtt-packet');
mqttPacket.writeToStream.cacheNumbers = false;
...
mqttPacket.writeToStream(packet, client.stream)
...

numCache would be initialized in the first call of writeToStream based on cacheNumbers prop (either generate cache or not). Potential draw back - a bit slower first call.

from mqtt-packet.

mcollina avatar mcollina commented on June 2, 2024

that'd be good for me.

from mqtt-packet.

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.