mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 06:08:50 +02:00
cluster: fix O(n*m) scan of cmd string
Don't scan the whole string for a "NODE_CLUSTER_" substring, just check that the string starts with the expected prefix. The linear scan was causing a noticeable (but unsurprising) slowdown on messages with a large .cmd string property.
This commit is contained in:
parent
cd96f0aba8
commit
dbbfbe74ca
1 changed files with 3 additions and 2 deletions
|
@ -141,9 +141,10 @@ cluster.setupMaster = function(options) {
|
||||||
// Check if a message is internal only
|
// Check if a message is internal only
|
||||||
var INTERNAL_PREFIX = 'NODE_CLUSTER_';
|
var INTERNAL_PREFIX = 'NODE_CLUSTER_';
|
||||||
function isInternalMessage(message) {
|
function isInternalMessage(message) {
|
||||||
return (isObject(message) &&
|
return isObject(message) &&
|
||||||
typeof message.cmd === 'string' &&
|
typeof message.cmd === 'string' &&
|
||||||
message.cmd.indexOf(INTERNAL_PREFIX) === 0);
|
message.cmd.length > INTERNAL_PREFIX.length &&
|
||||||
|
message.cmd.slice(0, INTERNAL_PREFIX.length) === INTERNAL_PREFIX;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Modify message object to be internal
|
// Modify message object to be internal
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue