Koenkk / zigbee-herdsman

A Node.js Zigbee library
MIT License
454 stars 278 forks source link

ZCL types revamp #1033

Closed Nerivec closed 6 days ago

Nerivec commented 1 week ago

TODO:

NOTE: zigate missing ParameterType values were added arbitrarily to allow compiling. It seems to also be missing types support. Code looks broken overall.

Nerivec commented 1 week ago

Some quick (i.e. imprecise) performance tests (x1000000):

BuffaloZcl Before After Change
read uint8 ~270ms ~200ms -25%
write uint8 ~190ms ~130ms -31%
read array ~680ms ~350ms -48%
write array ~750ms ~300ms -60%
read enum8 ~290ms ~200ms -31%
write enum8 ~220ms ~130ms -40%
read buffer ~310ms ~310ms -
write buffer ~530ms ~340ms -35%
BuffaloZcl read uint8 ```typescript for (let x = 0; x < 1000000; x++) { const buffalo = new BuffaloZcl(Buffer.from([0x00, 0x03, 0x00, 0x00]), 1); buffalo.read(Zcl.DataType.UINT8, {}); // buffalo.read('uint8', {}); } ```
BuffaloZcl write uint8 ```typescript for (let x = 0; x < 1000000; x++) { const buffalo = new BuffaloZcl(Buffer.alloc(3), 1); buffalo.write(Zcl.DataType.UINT8, 240, {}); // buffalo.write('uint8', 240, {}); } ```
BuffaloZcl read array ```typescript for (let x = 0; x < 1000000; x++) { const buffer = Buffer.from([32, 3, 0, 1, 2, 3]); const buffalo = new BuffaloZcl(buffer); buffalo.read(Zcl.DataType.ARRAY, {}); // buffalo.read('array', {}); } ```
BuffaloZcl write array ```typescript for (let x = 0; x < 1000000; x++) { const payload = {elementType: Zcl.DataType.DATA8, elements: [0, 0, 0, 0]}; // const payload = {elementType: Zcl.DataType.data8, elements: [0, 0, 0, 0]}; const buffer = Buffer.alloc(7); const buffalo = new BuffaloZcl(buffer); buffalo.write(DataType.ARRAY, payload, {}); // buffalo.write('array', payload, {}); } ```
BuffaloZcl read enum8 ```typescript for (let x = 0; x < 1000000; x++) { const buffalo = new BuffaloZcl(Buffer.from([0x00, 0x03, 0x00, 0x00]), 1); buffalo.read(Zcl.DataType.ENUM8, {}); // buffalo.read('enum8', {}); } ```
BuffaloZcl write enum8 ```typescript for (let x = 0; x < 1000000; x++) { const buffalo = new BuffaloZcl(Buffer.alloc(3), 1); buffalo.write(Zcl.DataType.ENUM8, 240, {}); // buffalo.write('enum8', 240, {}); } ```
BuffaloZcl read buffer ```typescript for (let x = 0; x < 1000000; x++) { const buffer = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05]); const buffalo = new BuffaloZcl(buffer); buffalo.read(BuffaloZclDataType.BUFFER, {}); // buffalo.read(BuffaloZclDataType[BuffaloZclDataType.BUFFER], {}); } ```
BuffaloZcl write buffer ```typescript for (let x = 0; x < 1000000; x++) { const buffer = Buffer.alloc(5); const expected = Buffer.from([0x01, 0x02, 0x03, 0x04, 0x05]); const buffalo = new BuffaloZcl(buffer); buffalo.write(BuffaloZclDataType.BUFFER, expected, {}); // buffalo.write(BuffaloZclDataType[BuffaloZclDataType.BUFFER], expected, {}); } ```