perf: optimize countWords function for large payloads#585
perf: optimize countWords function for large payloads#585Ashura707 wants to merge 4 commits intolingodotdev:mainfrom
Conversation
|
@maxprilutskiy could the lingo dev team check this and let me know |
| --- | ||
| --- |
There was a problem hiding this comment.
This needs a changeset if we want to release the change.
| const stack: any[] = [payload]; | ||
| let totalWordCount = 0; | ||
|
|
||
| while (stack.length > 0) { |
There was a problem hiding this comment.
How is this an optimization? If I am reading this right, the code is executed the same number of times as before. This is a micro-optimization at best (if while is faster than recursion), however I find this new code harder to read than before.
I'd like a second pair of eyes on this, @maxprilutskiy @7hacker please have a look.
There was a problem hiding this comment.
@mathio I can come up with a better optimization for this making it more readable.Should I make a new pr or add the changes in this branch?
There was a problem hiding this comment.
I raised my concerns in the issue. Lets continue the conversation there.
|
@Ashura707 we decided to take a different direction here. Good job optimizing the performance, however we prefer simplicity and better maintainability over maximum performance here. Sorry for not raising it internally before we opened an issue. |

Fix:#569

Before:
After:

->Removed recursion based approach and made it iterative to process it.Added test cases,
->Optimized processing speed of large payloads increasing the performance