Comments (9)
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.
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.
@kirilknysh so, how do you think we can make this configurable? Also, we might check if using an array improve things.
from mqtt-packet.
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.
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.
Sure, I'd love to attempt. One thing: how do you expect to get access to mqttPacket.cacheNumbers
from writeToStream.js
?
from mqtt-packet.
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.
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.
that'd be good for me.
from mqtt-packet.
Related Issues (20)
- Current Typescript definitions are difficult to use to read userProperties
- stop validating protocol level in this package HOT 1
- can't comply with MQTT spec requirements about flag validation HOT 1
- Generate 'puback' package can't set 'qos' properties HOT 5
- Buffer is not defined HOT 1
- SUBSCRIBE packet with no payload HOT 3
- Cannot connect to some MQTT server when the connect packet sent in chunk instead of full packet at once HOT 1
- No callback on writeToStream? HOT 5
- Call `stream.destroy(err)` instead of `stream.emit('error', err)` HOT 1
- Cannot specify subscription identifier when sending a SUBSCRIBE packet
- Publish v8.0.0 to NPM
- Are there any usage examples?
- Will mqtt-packet convert date to timestamp?
- numbers.js cache excessive memory usage HOT 2
- Connect packet HOT 1
- Mqtt 5 puback is different from spec HOT 6
- Typescript HOT 4
- Block-scoped declarations (let, const, function, class) not yet supported outside strict mode HOT 3
- Regression in v6.6.0 for parsing multi-byte length header that is split across write calls HOT 5
- Buffer out of bounds when v5 connection request sent to v4 server
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mqtt-packet.