How Data Structures Affect Programming Performance
跳到主要内容
Data structures are the underlying frameworks that organize and manage data in software, and the right choice can make programs run noticeably faster or slower. Selecting the proper data structure, or arranging data in memory wisely, is crucial for making everything from web apps to databases work smoothly and efficiently.
Match structure to task: Choose data structures based on how your program will use data, such as opting for dictionaries for quick lookups or trees for sorted information.
Think about memory layout: Arrange fields in custom data types and select cache-friendly structures to help your computer access and process information faster.
Adapt for special needs: Use specialized structures like ropes for editing large text files or B-trees for handling lots of data on disk, so your application stays fast as it grows.
由 AI 根据领英会员动态总结
Anton Martyniuk
Helping 100K+ .NET Engineers reach Senior and Software Architect level | Microsoft MVP | .NET Software Architect | AI Expert | Founder: antondevtips
105,249 位关注者
8 个月
举报此动态
关闭菜单
𝗬𝗼𝘂𝗿 𝗱𝗮𝘁𝗮 𝘀𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲 𝗰𝗵𝗼𝗶𝗰𝗲𝘀 𝗮𝗿𝗲 𝗸𝗶𝗹𝗹𝗶𝗻𝗴 .𝗡𝗘𝗧 𝗮𝗽𝗽 𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲
I optimized 12 enterprise ASP .NET Core systems and found the same problem every time.
Most developers spend hours tuning queries, adding indices, and implementing caching.
But they ignore the most critical performance factor: data structure selection.
The wrong collections can make your app 10x slower than needed.
Here's what to use based on your operation:
1. Finding items by key
List.Find() → O(n) → Terrible at scale
Dictionary → O(1) → Lightning fast
2. Frequently inserting at the beginning
List.Insert(0, item) → O(n) → Shifts all elements
LinkedList → O(1) → No shifting needed
3. Collection with unique items
List + Contains check → O(n) per add
HashSet → O(1) → Instant uniqueness checks
4. Ordered data with binary search
List + Sort → O(n log n) + manual search code
SortedDictionary → Built-in ordering + O(log n) lookup
5. API response caching
Static Dictionary → Memory leaks and stale data
MemoryCache with expiration → Automatic cleanup
I've seen teams waste days on complex optimizations when the right data structure would fix everything.
What is the biggest performance problem you solved by picking a correct data structure?
—
♻️ Repost to help others optimize their .NET apps
➕ Follow me ( Anton Martyniuk ) for more
—
…展开
无上一项内容
无下一项内容
Anton Martyniuk
Helping 100K+ .NET Engineers reach Senior and Software Architect level | Microsoft MVP | .NET Software Architect | AI Expert | Founder: antondevtips
𝗬𝗼𝘂𝗿 𝗱𝗮𝘁𝗮 𝘀𝘁𝗿𝘂𝗰𝘁𝘂𝗿𝗲 𝗰𝗵𝗼𝗶𝗰𝗲𝘀 𝗮𝗿𝗲 𝗸𝗶𝗹𝗹𝗶𝗻𝗴 .𝗡𝗘𝗧 𝗮𝗽𝗽 𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲
I optimized 12 enterprise ASP .NET Core systems and found the same problem every time.
Most developers spend hours tuning queries, adding indices, and implementing caching.
But they ignore the most critical performance factor: data structure selection.
The wrong collections can make your app 10x slower than needed.
Here's what to use based on your operation:
1. Finding items by key
List.Find() → O(n) → Terrible at scale
Dictionary → O(1) → Lightning fast
2. Frequently inserting at the beginning
List.Insert(0, item) → O(n) → Shifts all elements
LinkedList → O(1) → No shifting needed
3. Collection with unique items
List + Contains check → O(n) per add
HashSet → O(1) → Instant uniqueness checks
4. Ordered data with binary search
List + Sort → O(n log n) + manual search code
SortedDictionary → Built-in ordering + O(log n) lookup
5. API response caching
Static Dictionary → Memory leaks and stale data
MemoryCache with expiration → Automatic cleanup
I've seen teams waste days on complex optimizations when the right data structure would fix everything.
What is the biggest performance problem you solved by picking a correct data structure?
—
♻️ Repost to help others optimize their .NET apps
➕ Follow me ( Anton Martyniuk ) for more
—
…展开
540
64 条评论
赞
评论
复制
LinkedIn
Facebook
X
关闭菜单
分享
540
64 条评论
赞
评论
分享
复制
LinkedIn
Facebook
X
关闭菜单
Herik Lima
Senior C++ Software Engineer | Algorithmic Trading Developer | Market Data | Exchange Connectivity | Trading Firm | High-Frequency Trading | HFT | HPC | FIX Protocol | Automation
35,931 位关注者
3 个月
举报此动态
关闭菜单
Cache-Friendly Structs
Last week, we conducted a pool, and cache efficiency was one of the most requested topics. I’m really glad this one came up because cache-friendly data structures are one of the most critical factors in modern high-performance systems — and yet, many developers still underestimate how much performance depends on memory layout rather than algorithm complexity.
Modern CPUs, such as those designed by Intel, operate at extremely high speeds, but memory access remains relatively slow. To bridge this gap, processors use multiple levels of cache (L1, L2, L3). These caches store small portions of memory closer to the CPU, allowing much faster access compared to main RAM.
At first glance, a struct may appear to be just a simple grouping of fields. However, the way fields are ordered and accessed has a direct impact on performance. Struct layout determines how efficiently the CPU cache can load and reuse data. When structs are designed properly, the CPU can fetch useful data in fewer cache lines, reducing latency and improving throughput.
To demonstrate why cache-friendly structs matter in practice, consider the core principles that influence performance:
Spatial locality — accessing data that is physically close in memory
Temporal locality — reusing data that was recently accessed
Cache line utilization — maximizing useful data per cache fetch
Predictable memory access patterns — enabling hardware prefetching
Without these principles, CPUs spend more time waiting on memory than executing instructions. This leads to cache misses, pipeline stalls, and significant performance degradation — especially in systems that process millions of objects per second.
In practice, cache-friendly struct design provides something extremely valuable: efficiency.
The CPU can load fewer cache lines, reuse more data, and execute instructions continuously without waiting on memory. This is essential in performance-critical environments such as trading systems, real-time engines, and large-scale simulations.
One of the biggest strengths of cache-friendly design is that it improves performance without changing algorithms. Simply reorganizing fields can reduce memory stalls and dramatically increase throughput.
Below, we included a simple example showing how struct layout directly affects cache efficiency. Even in its minimal form, it illustrates how memory organization impacts performance.
And here’s the key takeaway:
Cache-friendly structs succeed because they prioritize memory locality, predictability, and efficient cache utilization over convenience.
In high-performance systems, memory layout is often more important than algorithm complexity. Struct design provides the foundation that allows modern CPUs to operate at their full potential.
Have you ever improved performance significantly just by reorganizing struct fields?
#Cpp #LowLatency #CacheFriendly #MemoryManagement #AlgorithmicTrading #EngineeringExcellence #SoftwareArchitecture
…展开
无上一项内容
无下一项内容
Herik Lima
Senior C++ Software Engineer | Algorithmic Trading Developer | Market Data | Exchange Connectivity | Trading Firm | High-Frequency Trading | HFT | HPC | FIX Protocol | Automation
Cache-Friendly Structs
Last week, we conducted a pool, and cache efficiency was one of the most requested topics. I’m really glad this one came up because cache-friendly data structures are one of the most critical factors in modern high-performance systems — and yet, many developers still underestimate how much performance depends on memory layout rather than algorithm complexity.
Modern CPUs, such as those designed by Intel, operate at extremely high speeds, but memory access remains relatively slow. To bridge this gap, processors use multiple levels of cache (L1, L2, L3). These caches store small portions of memory closer to the CPU, allowing much faster access compared to main RAM.
At first glance, a struct may appear to be just a simple grouping of fields. However, the way fields are ordered and accessed has a direct impact on performance. Struct layout determines how efficiently the CPU cache can load and reuse data. When structs are designed properly, the CPU can fetch useful data in fewer cache lines, reducing latency and improving throughput.
To demonstrate why cache-friendly structs matter in practice, consider the core principles that influence performance:
Spatial locality — accessing data that is physically close in memory
Temporal locality — reusing data that was recently accessed
Cache line utilization — maximizing useful data per cache fetch
Predictable memory access patterns — enabling hardware prefetching
Without these principles, CPUs spend more time waiting on memory than executing instructions. This leads to cache misses, pipeline stalls, and significant performance degradation — especially in systems that process millions of objects per second.
In practice, cache-friendly struct design provides something extremely valuable: efficiency.
The CPU can load fewer cache lines, reuse more data, and execute instructions continuously without waiting on memory. This is essential in performance-critical environments such as trading systems, real-time engines, and large-scale simulations.
One of the biggest strengths of cache-friendly design is that it improves performance without changing algorithms. Simply reorganizing fields can reduce memory stalls and dramatically increase throughput.
Below, we included a simple example showing how struct layout directly affects cache efficiency. Even in its minimal form, it illustrates how memory organization impacts performance.
And here’s the key takeaway:
Cache-friendly structs succeed because they prioritize memory locality, predictability, and efficient cache utilization over convenience.
In high-performance systems, memory layout is often more important than algorithm complexity. Struct design provides the foundation that allows modern CPUs to operate at their full potential.
Have you ever improved performance significantly just by reorganizing struct fields?
#Cpp #LowLatency #CacheFriendly #MemoryManagement #AlgorithmicTrading #EngineeringExcellence #SoftwareArchitecture
…展开
333
33 条评论
赞
评论
复制
LinkedIn
Facebook
X
关闭菜单
分享
333
33 条评论
赞
评论
分享
复制
LinkedIn
Facebook
X
关闭菜单
sukhad anand
Senior Software Engineer @Google | Techie007 | Opinions and views I post are my own
106,130 位关注者
2 个月
举报此动态
关闭菜单
Data structures aren't academic exercises. They're running your favorite systems right now.
Here's what's actually powering the infrastructure you use every day:
𝗥𝗮𝗱𝗶𝘅 𝗧𝗿𝗲𝗲𝘀 → API Gateways (NGINX, Kong) Every time your request hits an API gateway, it's not doing a naive string match across thousands of routes. It's walking a compressed prefix tree. O(k) lookup where k = URL length. That's how Kong handles 100K+ routes without breaking a sweat.
𝗕𝗹𝗼𝗼𝗺 𝗙𝗶𝗹𝘁𝗲𝗿𝘀 → Databases (Cassandra, LevelDB) Before hitting disk for a read, Cassandra asks a bloom filter: "Could this key exist in this SSTable?" If the answer is no, it skips the entire I/O. One probabilistic data structure saving millions of disk reads per second.
𝗦𝗸𝗶𝗽 𝗟𝗶𝘀𝘁𝘀 → Redis Redis didn't pick a red-black tree for sorted sets. It picked skip lists. Why? Simpler implementation, comparable O(log n) performance, and way easier to reason about for range queries. Sometimes the "textbook optimal" choice isn't the engineering optimal choice.
𝗟𝗦𝗠 𝗧𝗿𝗲𝗲𝘀 → Write-heavy databases (RocksDB, Cassandra) Every write goes to an in-memory memtable first, then flushes to sorted runs on disk. Turns random writes into sequential writes. This is why RocksDB can sustain millions of writes/sec on SSDs.
𝗖𝗥𝗗𝗧𝘀 → Collaborative editing (Figma, Redis) How does Figma let 50 designers edit the same file without conflicts? Conflict-free Replicated Data Types. The data structure itself guarantees eventual consistency. No central coordination needed.
𝗖𝗼𝘂𝗻𝘁-𝗠𝗶𝗻 𝗦𝗸𝗲𝘁𝗰𝗵 → Rate Limiters Tracking exact request counts per user at scale is expensive. A Count-Min Sketch gives you approximate frequency with fixed memory. Good enough for rate limiting. Way cheaper than a hash map per user.
𝗠𝗲𝗿𝗸𝗹𝗲 𝗧𝗿𝗲𝗲𝘀 → Git, Blockchain, Dynamo Every git commit, every block verification, every anti-entropy sync in Dynamo — all Merkle trees. Hash the children, propagate up, compare roots. O(log n) verification that two massive datasets are identical.
----
Breakdown of AI and complex systems: https://lnkd.in/gVm5dUHn
…展开
167
4 条评论
赞
评论
分享
复制
LinkedIn
Facebook
X
关闭菜单
Michael Drogalis
Simulate Kafka production traffic // Creator of shadowtraffic.io, helping software engineers replicate customer workloads
19,799 位关注者
10 个月
举报此动态
关闭菜单
Pop quiz: you're building a text editor and need to pick a data structure to represent the text. What do you choose?
If you said "string", keep reading.
String is the obvious choice for representing a character array, but the way it's stored (a contiguous block of memory) is terrible for mutable performance if the length is long.
Just look at its big O characteristics:
• concatenation: O(n + m)
• insertion: O(n)
• deletion: O(n)
• substring: O(m)
(n = original string length, m = new string length)
A text editor that models file content as strings would be SUPER slow for even moderately sized files.
This is what ropes are for.
Instead of storing the entire string as a block of memory, a rope represents the string as a balanced binary tree where leaves contain short substrings and parent nodes contain the summed lengths of the *left* subtree.
⚡ Balanced binary trees are MUCH faster for mutability:
• concatenation: O(log n + log m)
• insertion: O(log n)
• deletion: O(log n)
• substring: O(log n + log m)
By storing left-subtree substring lengths, ropes can efficiently seek around the tree and mostly get log n performance.
And that's why your editor responds quickly when you modify the middle of a large file.
…展开
无上一项内容
无下一项内容
Michael Drogalis
Simulate Kafka production traffic // Creator of shadowtraffic.io, helping software engineers replicate customer workloads
Pop quiz: you're building a text editor and need to pick a data structure to represent the text. What do you choose?
If you said "string", keep reading.
String is the obvious choice for representing a character array, but the way it's stored (a contiguous block of memory) is terrible for mutable performance if the length is long.
Just look at its big O characteristics:
• concatenation: O(n + m)
• insertion: O(n)
• deletion: O(n)
• substring: O(m)
(n = original string length, m = new string length)
A text editor that models file content as strings would be SUPER slow for even moderately sized files.
This is what ropes are for.
Instead of storing the entire string as a block of memory, a rope represents the string as a balanced binary tree where leaves contain short substrings and parent nodes contain the summed lengths of the *left* subtree.
⚡ Balanced binary trees are MUCH faster for mutability:
• concatenation: O(log n + log m)
• insertion: O(log n)
• deletion: O(log n)
• substring: O(log n + log m)
By storing left-subtree substring lengths, ropes can efficiently seek around the tree and mostly get log n performance.
And that's why your editor responds quickly when you modify the middle of a large file.
…展开
170
31 条评论
赞
评论
复制
LinkedIn
Facebook
X
关闭菜单
分享
170
31 条评论
赞
评论
分享
复制
LinkedIn
Facebook
X
关闭菜单
martinuke0
AI Contractor
638 位关注者
3 周
举报此动态
关闭菜单
Hi! Why B-Trees Outperform Binary Search Trees on Disk
> TL;DR — B‑trees store many keys per node, dramatically reducing the number of disk reads required to locate a record. Their wide fan‑out, cache‑friendly layout, and balanced update strategy make them far more efficient than binary search trees (BSTs) for persistent storage.
Disk‑based data structures face a fundamentally different cost model than in‑memory ones. While a CPU can fetch a word from RAM in nanoseconds, a single 4 KB disk block may take milliseconds to read. This disparity forces designers to batch work at the block level. B‑trees were created exactly for that purpose, whereas classic binary search trees (BSTs) were optimized for pointer‑rich, byte‑addressable memory. The result is a stark performance gap when both structures are placed on a hard drive or SSD.
Modern storage devices still exhibit a noticeable penalty for random reads compared to sequential scans. Even SSDs, which have no moving parts, have higher latency for scattered 4 KB reads because each request must traverse the flash translation layer. A BST forces a new block fetch at every node traversal because each node typically holds only a single key and two child pointers. In the worst case, locating a record of depth h triggers h separate I/O operations.
Read the full guide: https://lnkd.in/da2-caRY
#BTree #BinarySearchTree #DiskI/O #DataStructures #Performance
…展开
Why B-Trees Outperform Binary Search Trees on Disk
martinuke0.github.io
23
赞
评论
分享
复制
LinkedIn
Facebook
X
关闭菜单
Performance Optimization Techniques的更多内容
展开
收起
领英
© 2026
العربية (阿拉伯语)
বাংলা (孟加拉语)
Čeština (捷克语)
Dansk (丹麦语)
Deutsch (德语)
Ελληνικά (希腊语)
English (英语)
Español (西班牙语)
فارسی (波斯语)
Suomi (芬兰语)
Français (法语)
हिंदी (印地语)
Magyar (匈牙利语)
Bahasa Indonesia (印尼语)
Italiano (意大利语)
עברית (希伯来语)
日本語 (日语)
한국어 (韩语)
मराठी (马拉地语)
Bahasa Malaysia (马来语)
Nederlands (荷兰语)
Norsk (挪威语)
ਪੰਜਾਬੀ (旁遮普语)
Polski (波兰语)
Português (葡萄牙语)
Română (罗马尼亚语)
Русский (俄语)
Svenska (瑞典语)
తెలుగు (泰卢固语)
ภาษาไทย (泰语)
Tagalog (他加禄语)
Türkçe (土耳其语)
Українська (乌克兰语)
Tiếng Việt (越南语)
简体中文 (简体中文)
正體中文 (繁体中文)
关闭菜单
语言