Skip to content

Pre-processing: transitioning Pandas processing to Polars - #1255

Open
EngCaioFonseca wants to merge 6 commits into
devfrom
EngCaioFonseca/polars-surgical
Open

EngCaioFonseca wants to merge 6 commits into
devfrom
EngCaioFonseca/polars-surgical

Conversation

@EngCaioFonseca

@EngCaioFonseca EngCaioFonseca commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Change Description

Moves the heaviest pandas data processing in 8Knot to Polars 2.0, the main bottleneck on large orgs.
The change is surgical: 6 high-volume sites, with less app code than before. Charts and Plotly are unchanged.

What changed

  • New retrieve_from_cache_pl reads the cache straight into Polars (ADBC). The old loader and its other callers are untouched.
  • process_data now runs in Polars for: new contributors, contributor importance pie, activity cycle, commits over time and commit domains. Each chart converts to pandas once, on the small aggregated result, before plotting.
  • Shared helpers in preprocessing_utils: timestamp parsing, interval mapping and date-range filter.
  • Runtime moves to Python 3.12, since Polars 2.0 requires it. POLARS_MAX_THREADS=1 matches the single-task workers.

Behaviour changes (intended)

  • New contributors, weekly interval: fixed. It used to crash with invalid tzoffset.
  • Commit domains: a null author email no longer crashes the chart.
  • Contributor importance pie: ties at the top-k cutoff are broken by contributor id. Before, the order was arbitrary.

Benchmark (real cache data, 1 thread, as in production; pandas = current dev code)

Step chaoss (72k rows) kubernetes (4.4M contributor rows)
Cache read, contributors 81 → 74 ms (1.1×) 36.2 → 3.75 s (9.7×)
Cache read, commits 102 → 81 ms (1.25×) 0.89 → 0.51 s (1.7×)
new_contributor 209 → 8 ms (27×) 22.2 → 1.2 s (18×)
contrib_importance_pie 207 → 9 ms (23×) 21.0 → 0.37 s (57×)
contrib_activity_cycle 94 → 13 ms (7×) 0.87 → 0.11 s (8×)
commits_over_time 84 → 19 ms (4.5×) 0.79 → 0.28 s (2.9×)
commit_domains 128 → 60 ms (2×) 1.43 → 0.49 s (2.9×)

On kubernetes, a contributor chart goes from about 60 s to about 5 s from cache to figure. The gains grow with org size, and peak memory drops by 0.3–1.2 GB per chart.

How it was verified

  • Same output: for every chart and every option (intervals, date ranges, top-k), the Polars result was checked against the pandas code. It matched on synthetic data (1M rows, with edge cases like nulls, bad emails and ties), on real chaoss data and on real kubernetes data.
  • In the app: the full Docker stack was run on Python 3.12. The 4 affected pages were loaded twice each with real data. All charts rendered, and the worker logs had no errors.
  • Celery safety: confirmed that no Polars code runs at import time, so forked workers don't hang.
  • Review: independent code reviews.

Generative AI disclosure

Please select one option:

  • This contribution was NOT assisted or created by Generative AI tools.
  • This contribution was assisted or created by Generative AI tools.

If AI tools were used, please provide details below:
- What tools were used? Claude Opus 5.5
- How were these tools used? Draft, code review, testing.
- Did you review these outputs before submitting this PR? Yes.

Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Signed-off-by: Caio Fonseca <engcaiofonseca@protonmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Development

Successfully merging this pull request may close these issues.

2 participants