Skip to main content

Command Palette

Search for a command to run...

Day 2 of 90: HFT Prep – Memory Alignment & Binary Search Variants

Updated
2 min read
Day 2 of 90: HFT Prep – Memory Alignment & Binary Search Variants
S
Documenting my daily learnings as I prepare for SDE-1 roles at high-performance and HFT-focused companies. Passionate about systems, strong DSA, and building efficient backend infrastructure.

The Mission & Philosophy

Watch Day 2 on Youtube here

I’ve officially kicked off a 90-day challenge to break into top HFT firms like Graviton, Tower Research, and Jane Street. My goal isn't content creation; it’s about maintaining discipline and improving my ability to explain complex code—a critical skill for high-stakes interviews. I’m keeping it raw: no editing, no flashy setups, just engineering focus.

Finding Signal in the Noise

  • The Environment: I'm recording this with a Bhagavad Gita path happening right outside my house—it's very loud, but the work doesn't stop.

  • The "Rubber Duck": Meet Mr. Pangu, my penguin interviewer who helps me talk through logic when I get stuck.

  • The Tech: Running Fedora Linux with Hyperland on an Asus TUF gaming laptop. I’m an engineer first, so I’m using my built-in webcam to avoid wasting time on production.


Technical Deep Dive: C++ for High Performance

1. Struct Padding & Memory Alignment

I implemented a MarketOrder struct to demonstrate why memory layout is critical in high-frequency trading.

  • The Discovery: A struct with a double, int, char, and bool might seem like 14 bytes, but my system showed 16 bytes.

  • The Logic: On a 64-bit system, the compiler adds padding to ensure data is aligned to 8-byte boundaries.

  • The Optimization: By reordering members to put the largest types first, I reduced a different struct version from 24 bytes to 16 bytes.

  • The HFT Impact: This saves 8 bytes of memory per order, which can prevent millions of CPU cache misses and reduce the memory footprint by 33%.

2. Production-Level Coding Standards

  • No bits/stdc++.h: I'm moving away from competitive programming shortcuts and explicitly including headers like <iostream> for cleaner, production-ready code.

  • Namespace Discipline: I've stopped using using namespace std; to avoid naming conflicts, which is standard practice in high-performance environments.

  • Buffer Management: Using \n instead of std::endl to avoid unnecessary buffer flushes, which can be a performance bottleneck.


DSA: Binary Search Mastery

I tackled two fundamental problems that test precision with boundary conditions:

  • LeetCode 35 (Search Insert Position): Implemented binary search using an overflow-safe midpoint calculation: low + (high - low) / 2.

  • LeetCode 34 (First and Last Position in Sorted Array): This involved running binary search logic to find the specific range of a target value in O(log N) time.

Current Status: Day 2/90 Complete.

Next Steps: Continuing to strip away "content creator" habits and focus purely on nanosecond-level optimizations.

#HFT #C++ #90DayChallenge #LowLatency #QuantTrading #MAIT

More from this blog

Saksham's Blog on Learning

11 posts

I write about what I learn to become a high-paying quant dev!