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

feat: don't clone replay event data #21074

Merged
merged 3 commits into from
Mar 26, 2024
Merged

Conversation

pauldambra
Copy link
Member

@pauldambra pauldambra commented Mar 21, 2024

see: https://posthog.slack.com/archives/C0374DA782U/p1711031505674169?thread_ts=1711030142.540499&cid=C0374DA782U

@benjackwhite do you remember why we clone?

we reducing events so that every session in a batch handled by a consumer is represented by a single message

[
{sessionId: 1, events: [a]}, {sessionId: 1, events: [b]}, {sessionId: 2, events: [c]}, 
]

becomes

[
{sessionId: 1, events: [a, b]}, {sessionId: 2, events: [c]}, 
]

in doing that we clone each object, but the events array can be large

If we do not access the original array of messages after reducing then i think it's safe to reduce without cloning at all.

(looking at usage we parse each message into an array variable and then reduce those parsed messages into the array variable used elsewhere in the code so I think it's safe to not copy here)

@pauldambra pauldambra changed the title feat: clone once not every feat: don't clone replay event data Mar 21, 2024
@benjackwhite
Copy link
Contributor

I don't think thats true - the tests prove it

Copy link
Contributor

@xvello xvello left a comment

Choose a reason for hiding this comment

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

This is a step in the right direction. Cloning into reducedMessages would not be necessary if the source message were not available outside of this scope (as in, reduce messages as they are unmarshalled)

@pauldambra pauldambra merged commit 822cebc into master Mar 26, 2024
87 checks passed
@pauldambra pauldambra deleted the feat/clone-once-not-every branch March 26, 2024 11:30
@pauldambra
Copy link
Member Author

This is a step in the right direction.

Yep, I knew I'd not be able to make time to focus on this so decided to go for progress over perfection 😊

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.

3 participants