Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feature] Proposal to change recursive call in processHelper to iterative solution #1225

Closed
neilnaveen opened this issue Sep 5, 2023 · 3 comments
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@neilnaveen
Copy link
Contributor

Is your feature request related to a problem? Please describe.
The processHelper function currently employs tail recursion to avoid stack overflow, which is beneficial for stack safety. However, the current design has noticeable performance drawbacks when handling deeply nested structures, taking multiple seconds to process the example case.

Describe the solution you'd like
I suggest refactoring the processHelper function to use an iterative approach rather than a recursive one. This could potentially speed up the function's runtime performance, making it more efficient for handling deeply nested loops.

Additional context
Here is a Go code snippet to replicate the issue. When run, this test case takes multiple seconds to complete, signifying a need for optimization.

sd := SimpleDoc{  
   Issuer: "google.com",  
   Info:   "this is a cool document",  
   Nested: []SimpleDoc{},  
}  
cur := sd  
for i := 0; i < 4000; i++ {  
   k := SimpleDoc{Issuer: "google.com", Info: fmt.Sprintf("this is a cooler nested doc %d", i), Nested: []SimpleDoc{cur}}  
   cur = k  
}  
// marshal cur to json  
blob, _ := json.Marshal(cur)  
  
// create a document  
overflowDoc := processor.Document{  
   Blob:   blob,  
   Type:   simpledoc.SimpleDocType,  
   Format: processor.FormatJSON,  
}
@neilnaveen neilnaveen added the enhancement New feature or request label Sep 5, 2023
@lumjjb
Copy link
Contributor

lumjjb commented Sep 7, 2023

Thanks for opening the issue! @neilnaveen is this something you'd like to work on - or should i label it as help wanted!

@lumjjb lumjjb added the good first issue Good for newcomers label Sep 7, 2023
@neilnaveen
Copy link
Contributor Author

I will work on this. Thanks

@pxp928
Copy link
Collaborator

pxp928 commented Sep 11, 2023

completed with: #1245

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants