Program optimization
lastmod 2025-11-17created 2016-09-0371 edits
Program optimization, or software optimization, in information engineering refers to modifying a system so that some aspect of it works more efficiently or uses fewer resources. For example, a computer program can be optimized so that it runs faster, operates using less memory or other resources, or consumes less power. Such a system can be a single computer program, a collection of computers, or a complete network such as the Internet.
Performance Tuning
Performance tuning is the improvement of system performance. This is typically a computer application, but the same methods can be applied to economic markets, bureaucracies or other complex systems. The motivation for such activity is called a performance problem, which can be real or anticipated. Most systems will respond to increased load with some degree of decreasing performance. A system's ability to accept higher load is called scalability, and modifying a system to handle a higher load is synonymous to performance tuning.
Systematic tuning follows these steps:
- Assess the problem and establish numeric values that categorize acceptable behavior.
- Measure the performance of the system before modification.
- Identify the part of the system that is critical for improving the performance. This is called the bottleneck.
- Modify that part of the system to remove the bottleneck.
- Measure the performance of the system after modification.
- If the modification makes the performance better, adopt it. If the modification makes the performance worse, put it back the way it was.
This is an instance of the measure-evaluate-improve-learn cycle from quality assurance.
A performance problem may be identified by slow or unresponsive systems. This usually occurs because high system loading, causing some part of the system to reach a limit in its ability to respond. This limit within the system is referred to as a bottleneck.
A handful of techniques are used to improve performance. Among them are code optimization, load balancing, caching strategy, distributed computing and self-tuning.
Compiler
Memory
- Memory pool
- memcpy
- Direct memory access (DMA)
- Duffs device
- Zero-copy
- Paging
- Port-mapped I/O
- Memory-mapped I/O
- Memory-mapped file
- mmap
- OOM killer
- cgroup
Hardware
- PerformanceTuning:DiskIO
- Managing Disk Space - Issues that come up when disk space runs low.
- SSD (Hardware)
- SIMD
CPU
- Arithmetic logic unit - Explanation of CPU arithmetic operations.
- Load
- CPU cache
- NUMA
- Context Switching
Korean: 동기화 (Synchronization)
- Mutex
- Lock-free
- Compare-And-Swap (CAS)
- Read-Copy-Update (RCU)
- Reader-Writer lock
- Spinlock
- Blocking lock
- File lock
Process/Thread
- Multi-process
- Multi-threaded
- Green threads
- User level scheduling
- Work-stealing queue
- thread pool design
- Coroutine
- Async-await
Networking
- PerformanceTuning:NetworkIO
- I/O multiplexing
- DPDK
- XDP
TCP tuning
- Buffer size
- Window size
- Congestion control (Korean: 혼잡 제어)
- Nagle algorithm (Korean: 네이글 알고리즘)
Load Balancing
- L4/L7 load balancing
- Consistent hashing
- Distributed systems
- Connection pooling
- keep-alive
High Performance Browser Networking
- Site: [Highly recommended] hpbn.co - High Performance Browser Networking
- Download: Hpbn.co.tar.gz
Performance is a feature. This book provides a hands-on overview of what every web developer needs to know about the various types of networks (WiFi, 3G/4G), transport protocols (UDP, TCP, and TLS), application protocols (HTTP/1.1, HTTP/2), and APIs available in the browser (XHR, WebSocket, WebRTC, and more) to deliver the best—fast, reliable, and resilient—user experience.
- Networking 101
HTTP/Web
- Web cache
- Lighthouse
- Nginx#Performance Tunning - Tuning for high-performance Nginx
- WebProgramming:PerformanceTunning - Web optimization methods.
- Web development#Why your website should be under 14kB
- WebFont:PerformanceTunning - Web font optimization.
Network topology
Filesystem
- Direct I/O vs Buffered I/O
- Guaranteeing durability with fsync/fdatasync
- SSD TRIM
- write amplification
- Format
Programming language
- C++:BitHacks - Bitwise operation tips & tricks
- Python:PerformanceTunning
Database
- RDBMS:ProgramOptimization - RDBMS optimization.
- PostgreSQL:Performance
- ACID vs BASE tradeoffs
- Concurrency control by isolation level
- Connection pooling and prepared statements
- Query plan analysis and indexing strategy
- Sharding and replication design
Scalability and architecture
Horizontal/vertical scaling
- Stateless service design principles
- Session clustering and distributed caches
- Service mesh and microservice patterns
- Event-driven architecture and message queues
Distributed systems
- CAP theorem and consistency models
- Consensus algorithms (Raft, Paxos)
- Distributed tracing and observability
- Circuit breaker and bulkhead patterns
Monitoring and performance optimization
System metrics
- Difference between CPU utilization and load average
- Context switch rate and run queue depth
- Memory bandwidth and saturation
- Disk I/O patterns (sequential vs random)
Profiling
- Analyzing CPU bottlenecks with flame graphs
- Memory profiling (heap, leak detection)
- Using low-level tools such as perf and eBPF
- Application Performance Monitoring (APM)
Performance tuning
- Amdahl's law and the limits of parallelization
- Latency percentiles (p50, p95, p99)
- Queueing theory and Little's law
- Batch processing vs Streaming tradeoffs
Security and privileges
- Rate limiting and DDoS defense
- TLS/SSL performance optimization
- JWT vs session-based authentication
- Container security and privilege escalation
- Filesystem in Userspace (FUSE)
Stability
- Graceful shutdown and zero-downtime deployment
- Health check and readiness probe design
- Chaos engineering principles
- Backup and disaster recovery strategies
See also
Favorite site
- Wikipedia (en) Program optimization
- Wikipedia (en) description of Performance Tuning
- Dark Programmer :: An Intuitive Understanding of Optimization Techniques
- Computer Systems: Program Optimization (1) (inefficient function calls, inefficient memory references)
- Computer Systems: Program Optimization (2) (Loop Unrolling, Reassociation Transform, Separate Accumulators)
- Computer Systems: Machine Code - Floating Point
- [Recommended] Naver D2 - Handling Traffic on the Naver Main Page 1
- [Recommended] Software optimization resources (Optimization manuals; includes optimized code such as memory copying written in c and asm)
- Why Performance Matters | Web Fundamentals | Google Developers
- [Recommended] Don't Guess the Load on Your Server, Measure It 2
- Experiment: The Hidden Costs of Slow Build Times | GeekNews
- (Original) Experiment: The hidden costs of waiting on slow build times | The GitHub Blog
- Paying for better hardware is actually cheaper and better for developers (fewer distractions)
- In the experiment above, paying $4~5 more for build time saves over $40 for a solo developer and over $200 for a team of five, and also saves the hour lost to task switching
- Of course, at a large company spending $4~5 per build can add up, but the sunk productivity cost grows as well
References
- Application Performance Management
- C++
- C++:Tip
- CPU cache
- Data Plane Development Kit
- Deep learning:Performance Tuning
- Direct memory access
- Duffs device
- Lighthouse
- Load
- Managing Disk Space
- Network topology
- Nginx
- Paging
- PerformanceTuning:CUDA
- PerformanceTuning:DiskIO
- PerformanceTuning:NetworkIO
- PostgreSQL:Performance
- Python:PerformanceTunning
- RDBMS:ProgramOptimization
- SIMD
- Solid-state drive
- Streaming SIMD Extensions
- TCP congestion control
- VisualStudio:Optimization
- Web API
- WebProgramming:PerformanceTunning
- Zero-copy