Skip to content
This repository has been archived by the owner on May 3, 2022. It is now read-only.

Optimizations for clients & servers #237

Open
1 of 10 tasks
Raynos opened this issue Dec 6, 2015 · 2 comments
Open
1 of 10 tasks

Optimizations for clients & servers #237

Raynos opened this issue Dec 6, 2015 · 2 comments

Comments

@Raynos
Copy link
Contributor

Raynos commented Dec 6, 2015

I'm working on a fat heavy branch and I'm keeping notes of optimizations that we should backport everywhere

  • use this inside constructors, v8 literally pattern detects for this.foo = x and NOT self.foo =x
  • use bucket based OutPending() data structure instead of naive dictionary
  • use write ahead to avoid calling RW.byteLength. buf.write() returns bytes written, and with our offset tracking we can always backtrack and set frame.writeUInt32BE(finalOffset, 0)
  • use TCP_WRAP if process.version === 0.10.32 to go 30% faster.
  • use 512kb SlowBuffer pool instead of new Buffer()
  • use the arg2str or arg2buf trick.
  • use the caching headers + writeHead() & writeTail() trick.
  • use utf8slice and utf8write.
  • avoid reading arg1 as slice when we only need string anyway.
  • thread offset through frame parsing to avoid SlowBuffer#slice where possible.

cc @jcorbin @rf @kriskowal

@rf
Copy link
Contributor

rf commented Dec 7, 2015

Related to the first point -- the instanceof check really does happen every time and does have a cost.

@Raynos
Copy link
Contributor Author

Raynos commented Dec 7, 2015

Yep; we need to avoid the instanceof pattern in any constructors that are not public interface or any constructors that are O(n) requests or O(n) sockets

We may also need to rethink the instanceof pattern for public interfaces and maybe favor a node-core-style createX() function.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants