[AAP-103747] perf(tasks): avoid redundant JSONB serialization and reduce scheduler per-tick overhead #555
All Vouch review confidence checks passed
Residual risk 0.19 = Change Risk (0.48) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.48 · 557 lines diff across 6 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.378
Shallow Review Depth
shallow_review_depth
0.289
Real PR Conversation Timeline
1 comments
"Review active on #555"
general
weight: 0.35
redhat-chai-bot
Description
-
apps/core/json_utils.py: adds an optionalnormalized: bool = Falsekeyword argument tojson_size_bytes()so callers with already-normalized data can compute byte size without runningto_jsonable()a second time.-
apps/tasks/models.py: updatesHourlyMetricsCollection.save()andAnonymizedMetricsPayload.save()to passnormalized=Truetojson_size_bytes()and skip re-normalizing/re-sizing whenupdate_fieldsis passed without the JSON data column (automatically appendingdata_size_bytes/payload_size_byteswhen the data column is written). Also chains.defer("result_data", "error_message", "description")ontoTask.immediate_tasks(),Task.scheduled_tasks(), andTask.recurring_tasks().-
apps/tasks/collectors/send_anonymized_to_segment.py&apps/tasks/collectors/daily_anonymize_and_prepare.py: adds.select_related("daily_summary")to_get_payloads_to_send()and passes explicitupdate_fields(always including"modified") on status-only.save()calls.-
apps/tasks/cron_scheduler.py: fetches only IDs via.values_list("id", flat=True)in_fail_stuck_tasks()and cachesTASK_LOCKShashtext()IDs perUnifiedTaskSchedulerinstance in_cleanup_stale_advisory_locks().- Adds unit tests covering single-pass normalization,
update_fieldsSQL exclusion,select_related, deferred discovery queries, and per-instance lock hash caching.- Saving
HourlyMetricsCollection/AnonymizedMetricsPayloadwalked large nested JSON dicts twice, and status-only updates re-normalized and rewrote full multi-MB JSONB columns on every transition. Meanwhile, the periodic scheduler fetched unusedresult_datablobs and re-queried staticTASK_LOCKShashes every 30 seconds.- Eliminates duplicate
to_jsonable()walks, restricts status-transitionUPDATEs to changed scalar columns, prefetchesdaily_summary, defers unusedTaskcolumns on scheduler ticks, and caches lock hashes per scheduler instance. In paired benchmarks on a containerized reference deployment (RHEL 9.6, Python 3.12, Django 5.2, PostgreSQL 15, identical SHA-256 output digests):- JSON saves & Segment send transitions: 3.13× faster on status-transition sends (
5.219s → 1.669s), 1.60× faster overall (11.202s → 7.016s),-47.7 MiBpeak RSS,-10queries- Scheduler ticks (50 ticks): 5.68× faster (
7.947s → 1.399s),hashtextqueries50 → 1,-17.8 MiBpeak RSSType of Change
Self-Review Checklist
Testing Instructions
Prerequisites
make composeor local test DB)Steps to Test
1. Run lint and format checks:
2. Run the targeted test suites:
Expected Results
UPDATESQL without JSONB rewrites (withmodifiedupdated),daily_summaryprefetching, deferred scheduler discovery columns, and singlehashtextresolution per scheduler instance.