2

To send binary messages with WebSocket, I can use either Node.js Buffers or Typed Arrays.

Is there a significantly difference in term of performance between them ?

1 Answer 1

2

As they both utilise raw memory under the hood, I doubt you will find any noticeable performance differences in general. That being said, performance is usually more about how you use these structures.

As you should never prematurely optimise, it is unlikely that a choice between two with regards to performance is going to make any difference to your application. I would suggest choosing the type whose api best suits your needs, making your code more readable, and easier to debug. TypedArrays would allow you to have consistent code at both client and server, while Buffers don't need to be initialised to zero. Each would have other pros and cons.

If performance did eventually become an issue, these types could also easily be swapped out, and separately profiled.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.