Skip to content

feat: speed up messages replication by avoiding re-encoding JSON - #1602

Merged
edgurgel merged 3 commits into
mainfrom
feat/realtime-messages-avoid-encoding
Nov 4, 2025
Merged

edgurgel merged 3 commits into
mainfrom
feat/realtime-messages-avoid-encoding

Conversation

@edgurgel

@edgurgel edgurgel commented Nov 1, 2025 •

Copy link
Copy Markdown
Member

What kind of change does this PR introduce?

We can use the already JSON encoded payload and pass a Jason.Fragment instead of decoding to then re-encode when the message gets sent to a websocket.

The realtime.send function had to be patched to include the message id as part of the payload if the payload does not have already an id defined.

Also set fullsweet_after=20 as this process processes tons of messages & binaries generating a lot of garbage to be collected.

What is the current behavior?

We always Jason.decode! the messages.payload which is a jsonb. To then send this payload to all nodes. If there is some websocket listening it will then encode as JSON again.

What is the new behavior?

Passing the Jason.Fragment with the original payload it won't decode to re-encode and if there is a websocket listening it will not need to re-encode this part of the message payload.

Additional context

Add any other context or screenshots.

@edgurgel
edgurgel force-pushed the feat/realtime-messages-avoid-encoding branch from befdf0e to 93dc9da Compare November 1, 2025 19:43
@coveralls

coveralls commented Nov 1, 2025 •

Copy link
Copy Markdown

Coverage Status

coverage: 86.784% (-0.2%) from 86.977%
when pulling c50cc1c on feat/realtime-messages-avoid-encoding
into ced9ca3 on main.

@edgurgel
edgurgel force-pushed the feat/realtime-messages-avoid-encoding branch from 340f4d5 to 5c8e8fa Compare November 3, 2025 01:12
@edgurgel
edgurgel requested a review from filipecabaco November 3, 2025 01:14
@supabase supabase deleted a comment from blacksmith-sh Bot Nov 3, 2025
We can use the already JSON encoded payload and pass a Jason.Fragment
instead of decoding to then re-encode when the message gets sent to a
websocket
@edgurgel
edgurgel force-pushed the feat/realtime-messages-avoid-encoding branch from a610b23 to c50cc1c Compare November 4, 2025 08:47
@edgurgel
edgurgel merged commit 7c0b073 into main Nov 4, 2025
@edgurgel
edgurgel deleted the feat/realtime-messages-avoid-encoding branch November 4, 2025 20:17
@kiwicopple

Copy link
Copy Markdown
Member

🎉 This PR is included in version 2.61.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants