Can thousands of objects hurt performance

Case in point is how RoBrowser handles each incoming/outgoing packet.

First off, RoBrowser uses classes for each packet, there are thousands of packets and they will be instantiated every time they are received or sent.

The packets are defined here. Let us take #L2681 as an example:

// 0x204
PACKET.CA.EXE_HASHCHECK = function PACKET_CA_EXE_HASHCHECK() {
    this.HashValue  = '';

    this.build = function() {
        var pkt_len = 2 + 16;
        var pkt_buf = new BinaryWriter(pkt_len);

        pkt_buf.writeShort(0x204);
        pkt_buf.writeBinaryString(this.HashValue, 16);
        return pkt_buf;
    };
};

We can find that packet being instantiated here.

pkt           = new PACKET.CA.EXE_HASHCHECK();
pkt.HashValue = hash;
Network.sendPacket(pkt);

Though this is a packet that is only sent once, imagine if this was a packet that is sent thousand times like a Walk or Attack packet.

I am no expert in programming, oop or javascript but I have read a thing or two.

Notes:

  • Unlike RoBrowser which is written for the browser, my server will be written in node.js, purely server side.
  • RoBrowser is client side so it only handles its request from 1 server. While in my case, it'll handle all connected clients.

Questions:

  • Is RoBrowser's way of handling packets slow for a server architecture?
  • Is there a huge difference in performance between using classes and not?

I'm looking for references on this topic (packet handling). If you know any, please do tell.

Defining object methods this way would create new functions for every instantiated object - bad for many objects :-(

With the prototype-way, only one method is created on the prototype object, that is shared by all instances:

// 0x204
PACKET.CA.EXE_HASHCHECK = function PACKET_CA_EXE_HASHCHECK() {
 this.HashValue  = '';
};

PACKET_CA_EXE_HASHCHECK.prototype.build = function() {
    var pkt_len = 2 + 16;
    var pkt_buf = new BinaryWriter(pkt_len);

    pkt_buf.writeShort(0x204);
    pkt_buf.writeBinaryString(this.HashValue, 16);
    return pkt_buf;
};