Skip to content

perf: reduce auth header allocations and validate before async#316

Open
KENILSHAHH wants to merge 4 commits intoPolymarket:mainfrom
KENILSHAHH:perf/order-builder-and-auth-headers
Open

perf: reduce auth header allocations and validate before async#316
KENILSHAHH wants to merge 4 commits intoPolymarket:mainfrom
KENILSHAHH:perf/order-builder-and-auth-headers

Conversation

@KENILSHAHH
Copy link
Copy Markdown

@KENILSHAHH KENILSHAHH commented Apr 2, 2026

Summary

  • Replace to_string().parse() with HeaderValue::from() for integer header values (timestamps, nonces), eliminating throwaway heap allocations on every authenticated
    request
  • Format UUID API keys into stack-allocated [u8; 36] buffers instead of heap-allocating via to_string()
  • Move size validation (missing, scale, zero/negative) above fee_rate_bps() and tick_size() async calls in the limit order builder so invalid orders fail immediately
    without network round-trips

Test plan

  • All 527 existing tests pass with --all-features
  • Auth header tests verify identical output values
  • Order builder tests confirm validation error messages unchanged

Note

Medium Risk
Touches request authentication header construction and limit-order validation ordering; while behavior should be equivalent, mistakes could break authenticated calls or change validation timing in a trading-critical path.

Overview
Reduces per-request allocations in auth header generation by constructing numeric headers via HeaderValue::from(...) and formatting UUID API keys into a stack buffer (instead of to_string().parse()) across L1/L2 and Builder local auth flows.

Reorders limit order validation in OrderBuilder<Limit>::build so size checks (missing/scale/non-positive) happen before async fee_rate_bps/tick_size calls, causing invalid orders to fail immediately without network round-trips.

Written by Cursor Bugbot for commit 868c3a8. This will update automatically on new commits. Configure here.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.56%. Comparing base (a5dc726) to head (868c3a8).

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #316      +/-   ##
==========================================
+ Coverage   85.54%   85.56%   +0.02%     
==========================================
  Files          32       32              
  Lines        5167     5175       +8     
==========================================
+ Hits         4420     4428       +8     
  Misses        747      747              
Flag Coverage Δ
rust 85.56% <100.00%> (+0.02%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

KENILSHAHH and others added 3 commits April 2, 2026 13:12
@KENILSHAHH
Copy link
Copy Markdown
Author

Would love the feedback here @chaz-polymarket

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.

1 participant