Skip to content

hoist get_required_fields out of to_headers#3323

Open
okradze wants to merge 1 commit intolatent-to:stagingfrom
okradze:fix/to-headers-perf
Open

hoist get_required_fields out of to_headers#3323
okradze wants to merge 1 commit intolatent-to:stagingfrom
okradze:fix/to-headers-perf

Conversation

@okradze
Copy link
Copy Markdown

@okradze okradze commented Apr 22, 2026

Summary

Fixes #3322

Synapse.to_headers() calls self.get_required_fields() on every iteration of its field loop. get_required_fields() rebuilds model_json_schema() each time, which is expensive. For a synapse with N fields the schema is rebuilt N times per call, so to_headers() slows down as the synapse grows. Since to_headers() runs on every outgoing dendrite request, this adds latency to all subnet traffic.

For a 20-field synapse with nested pydantic types: 68.77 ms/call → 2.51 ms/call (~27× speedup).

Changes

bittensor/core/synapse.py:

  • Hoist required = self.get_required_fields() out of the field loop in to_headers(). Reduces calls from N to 1; behavior unchanged.

@okradze okradze force-pushed the fix/to-headers-perf branch from 7fb625e to 3b6680c Compare April 22, 2026 20:55
@thewhaleking
Copy link
Copy Markdown
Contributor

Hey @okradze we require commits to be signed

@okradze okradze force-pushed the fix/to-headers-perf branch from 3b6680c to 9ef6bae Compare April 24, 2026 07:30
@thewhaleking
Copy link
Copy Markdown
Contributor

Screenshot 2026-04-24 at 09 32 02

You'll need to also upload your GPG key…

@okradze
Copy link
Copy Markdown
Author

okradze commented Apr 24, 2026

@thewhaleking Thanks, fixed now

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.

2 participants