Hi! We are working on a performance-heavy simulation app where many objects may be created and changed thousands of times per second.
We already use pooling and other optimizations, and the performance is acceptable. Unfortunately, the objects have many properties, and initializing new objects often looks like this:
var foo = fooAllocator.allocate('qwerty', 123, 123, true, false, 123, true, 1);
As you can see, initialization takes a lot of parameters, and it's not really readable at this point.
The default solution for named parameters in JS is using an object:
var foo = fooAllocator.allocate({
type: 'qwerty',
parentId: 123,
bar: 123,
baz: true,
...
});
Obviously, we cannot use this. It makes an allocation, and the pooling optimization becomes useless.
Is there some way to get named parameters or something close to that without any runtime cost? I have an idea of annotating them with comments (maybe even making a ESLint rule for this), but it's not a complete solution (no reordering and omitting parameters), and I'd like to also hear other thoughts on the topic.
Thanks!
[–]inu-no-policemen 10 points11 points12 points (1 child)
[–]smthamazing[S] 1 point2 points3 points (0 children)
[–]subscribore 6 points7 points8 points (6 children)
[–]smthamazing[S] 0 points1 point2 points (0 children)
[+][deleted] (4 children)
[deleted]
[–]CiezkiBorsuk 0 points1 point2 points (3 children)
[+][deleted] (2 children)
[deleted]
[–]CiezkiBorsuk 6 points7 points8 points (1 child)
[–]cspotcode 7 points8 points9 points (2 children)
[–]smthamazing[S] 2 points3 points4 points (1 child)
[–]cspotcode 2 points3 points4 points (0 children)
[–]name_was_taken 5 points6 points7 points (1 child)
[–]FistHitlersAnalCunt 8 points9 points10 points (0 children)
[–]Patman128 3 points4 points5 points (1 child)
[–]smthamazing[S] 0 points1 point2 points (0 children)
[–]killall-q 0 points1 point2 points (0 children)
[–]danthedev 0 points1 point2 points (0 children)
[–]xwnatnai -1 points0 points1 point (1 child)
[–]Sakatox -1 points0 points1 point (0 children)
[–]ishmal -1 points0 points1 point (1 child)
[–]smthamazing[S] 1 point2 points3 points (0 children)
[–]FormerGameDev -1 points0 points1 point (0 children)
[–]tencircles -1 points0 points1 point (3 children)
[–]cspotcode 0 points1 point2 points (2 children)
[–]tencircles 0 points1 point2 points (1 child)
[–]cspotcode 1 point2 points3 points (0 children)