Skip to content

Commit

Permalink
feat(sync-service): Move WHERE clause evaluation to single process (#…
Browse files Browse the repository at this point in the history
…1761)

This is the simplest change to meet the criteria of #1744 .

It's faster and uses less memory:
<img width="795" alt="Screenshot 2024-10-10 at 13 48 21"
src="https://github.com/user-attachments/assets/a508d078-9cbd-4610-babb-909d66de682e">

Than our current version:
<img width="790" alt="Screenshot 2024-10-10 at 13 48 38"
src="https://github.com/user-attachments/assets/a1a0d0da-39fd-4201-b468-5aa64a649120">

Because of the reduction in memory use it can handle bigger transactions
at 100k shapes:
<img width="824" alt="Screenshot 2024-10-10 at 13 36 12"
src="https://github.com/user-attachments/assets/da0a62f8-97c6-4dee-b63b-a8222ed54856">

vs our la
<img width="822" alt="Screenshot 2024-10-10 at 13 35 59"
src="https://github.com/user-attachments/assets/2f7aec8b-e840-49ba-b4b7-2d4733b264f9">
test version:
  • Loading branch information
robacourt authored Oct 10, 2024
1 parent ef07605 commit c2076c8
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion packages/sync-service/lib/electric/shapes/consumer.ex
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,18 @@ defmodule Electric.Shapes.Consumer do
monitors: []
})

{:consumer, state, subscribe_to: [{producer, [max_demand: 1, selector: nil]}]}
{:consumer, state,
subscribe_to: [{producer, [max_demand: 1, selector: &selector(&1, config.shape)]}]}
end

defp selector(%Transaction{changes: changes}, shape) do
changes
|> Stream.flat_map(&Shape.convert_change(shape, &1))
|> Enum.any?()
end

defp selector(_, _), do: false

def handle_call(:initial_state, _from, %{snapshot_xmin: xmin, latest_offset: offset} = state) do
{:reply, {:ok, xmin, offset}, [], state}
end
Expand Down

0 comments on commit c2076c8

Please sign in to comment.