Repository navigation
Mutations table: read copy number for the table's genes only; compute its rows once - #502
Merged
Merged
Conversation
… its rows once The Mutations tab's first draw went from 3.5s to 16.7s (coadread KRAS) and 4.4s to 24.8s (msk_chord TP53) between 140c923 and b12e240. Two things in the table's statement cause it: - The copy-number lookup (cn<i>) has read every gene's discrete CNA call for the table's samples since 96a8c05, about 12.7M rows of genetic_alteration_derived per statement on msk_chord. It now reads only the queried gene and the fusion rows' site 1 genes, the only keys its two joins (cn.g = gene, cn.g = v.gene1) ever match. - The mutation and fusion rows (m<i>, v<i>) are referenced 21 times in the statement, and ClickHouse inlines a CTE at each reference. Where the connection runs enable_materialized_cte (materializedCteSupported, as the other views already ask), they are now AS MATERIALIZED and every row statement (page, counts, values, rank) ends with the setting, via a new RowSource.settings. Recorded-answer runs (snapshots) stay plain. The rows are unchanged. Verified: - Replaying the captured msk_chord TP53 counts statement: 35.8M rows read and 4.0-4.6s before, 3.5M and 0.75-1.2s with both changes. - /api/analysis mutations tables from b12e240 and this branch are identical (rows, totals, Copy # values) for msk_chord TP53/ALK/TMPRSS2 (315 fusion rows)/KRAS, coadread KRAS/APC and msk_impact_2017 EGFR. - Browser benchmark, cold, fully drawn: coadread KRAS 16.5s -> 4.2s (baseline 3.3s); msk_chord TP53 18.5s -> 7.3s (baseline 3.6s). - Tests: the mutation table's page, counts and values statements join the materialized case table (text: exactly m0 and v0 materialized and the setting appended; fixture: the same rows as the plain statement, 3 genes x 2 cohorts). A new fixture check (F3) compares every row with and without the gene condition, including ALK fusion rows. The mutations snapshot is re-recorded; only its copy-number condition changed, its results are byte-identical. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q3ezTZuofAGZDqqTqBUcTu
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The Mutations tab got 5× slower between 140c923 and b12e240. Its first draw went from 3.5s to 16.7s on coadread (KRAS) and from 4.4s to 24.8s on msk_chord (TP53). This PR removes most of that slowdown and leaves the table's contents unchanged.
Cause
Two parts of the table's row statement (
mutationRowSource) do most of the extra reading:cn<i>reads every gene's discrete CNA call for the table's samples. On msk_chord that is about 12.7M rows ofgenetic_alteration_derivedper statement. Its joins only ever match the queried gene (cn.g = gene) and the fusion rows' site 1 genes (cn.g = v.gene1). It now reads only those genes.m<i>andv<i>21 times, and ClickHouse recomputes a CTE at each reference. Where the connection supportsenable_materialized_cte(materializedCteSupported, the check the other views already use), they are nowAS MATERIALIZED. Each row statement (page, counts, values, rank) ends with the setting through a newRowSource.settings. Runs from recorded answers (the snapshots) keep the plain statements.Replaying the captured msk_chord TP53 counts statement:
Result
Browser benchmark with production builds, cold loads, until the page is fully drawn. Medians of 3 loads for coadread and 6 for msk_chord:
msk_chord is still about 2× its time on 140c923. The rest comes from two things this PR doesn't touch:
Verification
/api/analysisreturned identical mutations tables from b12e240 and this branch: rows, totals and Copy # values. Cases:test/support/view-mcte-cases.ts. The test checks that exactlym0andv0are materialized and that the setting is appended. These tests fail without the change.view-materialized-fixture, materialized and plain statements return the same rows, for 3 genes × 2 cohorts.npm testhas two failures that are not from this change:view-materialized-fixturefails with no fixture database. It fails the same way on master.npx tsc --noEmit, eslint and knip are clean.scripts/gate.sh.🤖 Generated with Claude Code
https://claude.ai/code/session_01Q3ezTZuofAGZDqqTqBUcTu
Open in [code]smith · Need help on this PR? Tag
@codesmith-botwith what you need.