Skip to content

Refactor Lists to Arrays - #127

Merged
JonoPrest merged 8 commits into
mainfrom
jp/refactor-lists-to-array
Aug 20, 2024
Merged

Refactor Lists to Arrays#127
JonoPrest merged 8 commits into
mainfrom
jp/refactor-lists-to-array

Conversation

@JonoPrest

Copy link
Copy Markdown
Collaborator
  • Remove use of lists holding eventBatchQueueItem
  • Where nodes of lists were returned, replace with a lazy computation on the original orray

@JonoPrest
JonoPrest requested a review from DZakh August 19, 2024 16:14
@JonoPrest
JonoPrest force-pushed the jp/refactor-lists-to-array branch from a4324d0 to 7a65760 Compare August 19, 2024 16:43
@JonoPrest
JonoPrest force-pushed the jp/reorg-detection-trampoline branch 2 times, most recently from bba5d06 to efd937c Compare August 19, 2024 17:47
@JonoPrest
JonoPrest force-pushed the jp/refactor-lists-to-array branch from 357abaf to e051c81 Compare August 19, 2024 17:50
Base automatically changed from jp/reorg-detection-trampoline to main August 19, 2024 17:54
@JonoPrest
JonoPrest force-pushed the jp/refactor-lists-to-array branch from e051c81 to 394eb5b Compare August 19, 2024 17:57
@JonoPrest

Copy link
Copy Markdown
Collaborator Author

Busy fixing a few bugs 👍🏼

@JonoPrest
JonoPrest marked this pull request as draft August 20, 2024 08:26
@JonoPrest
JonoPrest marked this pull request as ready for review August 20, 2024 10:04
@JonoPrest

Copy link
Copy Markdown
Collaborator Author

Hey @DZakh, the organize utils PR is based on top of this so I won't merge it until this is reviewed so it's a bit easier to separate out the changes.

Comment thread codegenerator/cli/templates/static/codegen/src/EventProcessing.res Outdated
Comment thread codegenerator/cli/templates/static/codegen/src/eventFetching/ChainManager.res Outdated
Comment thread codegenerator/cli/templates/static/codegen/src/eventFetching/ChainManager.res Outdated
let getFirstArbitraryEventsItem = (queue: array<Types.eventBatchQueueItem>) =>
switch queue[0] {
| None => None
| Some(first) => Some((first, () => Array.sliceToEnd(queue, 1)))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note how I've made all these slice operations lazy. So that they only get run if the item on this queue is actually chosen.

@JonoPrest
JonoPrest force-pushed the jp/refactor-lists-to-array branch from 3654613 to 5abddb1 Compare August 20, 2024 14:02

@DZakh DZakh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think ideally for the arbitaryQueue instead of merging everything into a single array with sorting and cloning it on every change we should have:

  1. An array for each chain (and maybe for every contract registration)
  2. Metadata which item we consumed for every array
  3. Metadata which array is consuming and a condition when it should switch to processing another one (we can get it from the smallest eventCmp of the first array item)
  • This way it's easier to find an item to process for a specific chain
  • Don't need to apply sorting for every item, and only run the check to figure out from which array to get the item next
  • Don't need to recreate an array on consuming an item - only increase the pointer index
  • When adding more items, just concat them to the array

But it's a bigger refactoring, I don't say we need to do it now. I'll continue reviewing the current changes.

@DZakh DZakh left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks amazing 🚀

Still a little bit painful to look at all the slices and concats, but already a huge improvement!

)
| EventFetchers(item, fetchStatesMap) => (arbitraryEventQueue, fetchStatesMap, item)
}
let _ = batch->Js.Array2.push(nextItem)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it ok to push here?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah "batch" is internal to this function.

@JonoPrest

Copy link
Copy Markdown
Collaborator Author

Cool. Lets chat about your points in person, it will be easier 👍🏼 some of them very valid but as you said part of a bigger refactor.

@JonoPrest
JonoPrest force-pushed the jp/refactor-lists-to-array branch from 5abddb1 to a0428dd Compare August 20, 2024 14:25
@JonoPrest
JonoPrest enabled auto-merge (squash) August 20, 2024 14:31
@JonoPrest
JonoPrest merged commit 080b260 into main Aug 20, 2024
@JonoPrest
JonoPrest deleted the jp/refactor-lists-to-array branch August 20, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants