posthog icon indicating copy to clipboard operation
posthog copied to clipboard

perf: Speed up filtering persons

Open timgl opened this issue 4 months ago • 11 comments

Problem

Currently, we first group/argmax every single person, then we filter that result set down. It'd be much faster to filter first, then group by.

Changes

Filter first, then group by, then filter again to make sure the results are still correct.

The resulting query is a bit ugly (basically 3 sub queries) but it takes the filtering of the persons page for researchgate down from 80-90 seconds to 2 seconds!

Also removed the personsArgMaxVersion and optimizeJoinedFilters modifiers as those were making things more complicated and weren't relevant anymore.

👉 Stay up-to-date with PostHog coding conventions for a smoother review.

Does this work well for both Cloud and self-hosted?

How did you test this code?

timgl avatar Oct 15 '24 17:10 timgl