Reduce/remove object allocations
- Dominant language
- JavaScript
- Stars
- 92
- Forks
- 34
- PR merge metrics
- No merged PRs in 30d
Description
I feel like there are a lot places where we can either recycle objects or just not allocate at all. One quick actionable item is to remove any POJO arguments e.g.
```
new Foo({ bar: 'bar', baz: 1 });
```
These are typically short lived objects that need to be GCd since all we typically do is peel them off in the constructor. Possibly run into [this issue](https://docs.google.com/document/d/1VEeXn6BfKmVkYpfMuxNs3otLLNPIxIVA1cLoSwGMIxI/edit) in hot paths. To make this a bit more palatable you can write the arguments to a constructor like this.
```ts
class Foo {
public someNum: number;
constructor(
public bar: string = 'default',
private baz: number = 0
) {
this.sumNumber = baz * 10;
}
}
```
This is equivalent to the following:
```ts
class Foo {
public bar: string = 'default';
private baz: number = 0;
public sumNumber: number;
constructor(bar: string, baz: number) {
this.bar = bar;
this.baz = baz;
this.sumNumber = baz * 10;
}
}
```
Since we have types getting argument position correct is less of an issue. Typically if there are more than 4 args to a class there is likely another object in there hiding.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.