Skip to content

Conversation

@magnetised
Copy link
Contributor

@magnetised magnetised commented Nov 27, 2025

This is part 1 of #3511.

Rather than loading a shape handle from the ShapeStatus LUTs using the Shape definition and then checking that it matches the one in the request params, we instead do a simple check that the request's handle and shape definition match using a hash equality check.

We only do a shape def -> handle lookup if the request doesn't have a handle parameter or the hash check fails.

I've also replaced use of fetch_shape_by_handle as the implementation of has_shape? with a lookup that just uses metadata.

This is an intermediate step - the next PR will move the shape out of the meta table completely and encapsulate shape lookups as a separate module.

Fixes #3512

@codecov
Copy link

codecov bot commented Nov 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 75.28%. Comparing base (331676d) to head (2c4f4c0).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3515      +/-   ##
==========================================
- Coverage   75.31%   75.28%   -0.04%     
==========================================
  Files          51       51              
  Lines        2743     2743              
  Branches      405      409       +4     
==========================================
- Hits         2066     2065       -1     
- Misses        675      676       +1     
  Partials        2        2              
Flag Coverage Δ
electric-telemetry 22.99% <ø> (+0.27%) ⬆️
elixir 57.65% <ø> (-0.09%) ⬇️
elixir-client 74.20% <ø> (-0.27%) ⬇️
packages/experimental 87.73% <ø> (ø)
packages/react-hooks 86.48% <ø> (ø)
packages/typescript-client 92.98% <ø> (ø)
packages/y-electric 55.12% <ø> (ø)
typescript 87.39% <ø> (ø)
unit-tests 75.28% <ø> (-0.04%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@magnetised magnetised force-pushed the magnetised/validate-shape-params-using-hash branch from 7120731 to b793517 Compare November 27, 2025 14:44
@msfstef
Copy link
Contributor

msfstef commented Nov 27, 2025

Beat me to it, this is exactly what I was also thinking while working on shape status! gmta

(can't review but saw this pop up and was happy haha)

Copy link
Contributor

@robacourt robacourt left a comment

Choose a reason for hiding this comment

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

Nice!

Copy link
Contributor

@msfstef msfstef left a comment

Choose a reason for hiding this comment

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

I think this is a net positive to maintain the benefits of requests where a shape handle is provided!

For the next step of what to do with the shape def -> handle lookup, I think I would go a step further than what you discuss in the followup issues, happy to chat about it!

def dependency_handles_known?(%__MODULE__{} = shape),
do: shape.shape_dependencies_handles != []

def hash(%__MODULE__{} = shape),
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm against having two separate places in code that return the "hash" of the shape, as they risk going out of sync with each other. I think we can deprecate this hash call and use comparable_hash everywhere we need the hash potentially. IMO a single public API returns the hash.

@magnetised magnetised force-pushed the magnetised/validate-shape-params-using-hash branch 2 times, most recently from 89cf5c1 to e7d419c Compare December 2, 2025 11:23
magnetised and others added 2 commits December 2, 2025 11:33
…idation

This is part 1 of #3511.

Rather than loading a shape handle from the ShapeStatus LUTs using the
Shape definition and then checking that it matches the one in the
request params, we instead do a simple check that the request's handle
and shape definition match using a hash equality check.

We only do a shape def -> handle lookup if the request doesn't have a
handle parameter or the hash check fails

Fixes #3512
#3518)

This is essentially what we have now but with a clear api between fast
metadata lookups and shape -> handle and handle -> shape lookups.

This moves the %Shape{} instances out of the metadata table and gives a
hint of the memory savings to come, this is for ~150K (very simple)
shapes:

```
shapedb:shape_lookup:single_stack    | 149432       | 242.7575 MiB
shapedb:handle_lookup:single_stack   | 149432       | 83.1469 MiB
shape_meta_table:single_stack        | 149432       | 29.5633 MiB
shape_relation_lookup_table:single_s | 149432       | 19.3010 MiB
shape_last_used_table:single_stack   | 149432       | 15.8808 MiB
```

You can see that the shapedb tables are responsible for most of the ets
usage and the metadata now only consumes ~30MiB, so a ~90% reduction,
which means we shouldn't have to go any further and move more things out
of ram.

The current api is not going to work for a sqlite backed version, but
it's close I think.

Fixes #3513
@magnetised magnetised force-pushed the magnetised/validate-shape-params-using-hash branch from e7d419c to 2c4f4c0 Compare December 2, 2025 11:33
@magnetised magnetised merged commit 4d8e61f into main Dec 2, 2025
47 checks passed
@magnetised magnetised deleted the magnetised/validate-shape-params-using-hash branch December 2, 2025 11:38
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.

Validate API request handles without requiring a shape -> handle LUT

4 participants