Tag: Optimization
22 posts
-
Finding and Fixing Slow React Renders: memo, useMemo, useCallback, Code Splitting and Profiling
Measure React re-renders with DevTools and the Profiler API, then fix them with React.memo, useMemo, useCallback, virtualization and code splitting.
-
C++ Inline Assembly: GCC Extended asm, Constraints and Clobbers, and Why Intrinsics Usually Win
C++ inline assembly (asm): GCC/Clang extended asm with constraints and clobbers, why MSVC x64 has no inline asm, CPUID/RDTSC done correctly, the optimizer rules that break asm blocks, and the intrinsics that replace most of them.
-
C++ Performance Optimization: Measure First, Then Copies, Allocations, Cache and Compiler Flags
A measured approach to C++ performance: profile first, remove hidden copies, reserve allocations, fix memory access order, and use -O2/-O3, -march and LTO without the common traps.
-
C++ RVO and NRVO: Copy Elision and Why return std::move(local) Backfires
RVO vs NRVO, C++17 guaranteed elision for prvalues, why std::move on return blocks NRVO, what benchmarks really show, and a practical checklist.
-
How Webpack 5 Builds a Bundle: Dependency Graph, Tapable Hooks, Loaders, Splitting and Tree Shaking
Webpack 5 deep dive: dependency graph, Tapable hooks, loader pipeline, code splitting, tree shaking, and production caching.
-
C++ Alignment and Padding: Why sizeof Surprises You, alignas, #pragma pack and False Sharing
Where struct padding comes from, how member order changes sizeof, what alignas and #pragma pack really do, why packed structs are risky, and false sharing.
-
C++ Branch Prediction: Measuring Mispredictions, cmov, [[likely]] and PGO
How branch mispredictions slow C++ loops, why the sorted-array trick depends on your compiler, and when cmov, [[likely]], partitioning or PGO actually help.
-
React useMemo and useCallback: When to Use Them
When useMemo and useCallback actually pay off in React: expensive computations, stable references for memo children, effects and Context values, dependency-array pitfalls, and verifying with the Profiler.
-
Core Web Vitals Checklist: Improving LCP, CLS and INP
Improve LCP with resource priority and images, stabilize CLS with dimensions and fonts, and reduce INP by shrinking main-thread work—field data.
-
RVO vs NRVO: When C++ Compilers Elide Copies, and When std::move Makes It Worse
RVO vs NRVO: when the compiler elides copies on return, C++17 guaranteed elision for prvalues, NRVO heuristics, and interaction with move semantics.
-
C++ Compiler Comparison: GCC vs Clang vs MSVC — Which Should
A comparison of GCC, Clang, and MSVC covering compilation stages, optimization flags, and diagnostic differences.
-
C++ inline Functions: ODR, Headers, and Compiler Inlining
C++ inline keyword: linkage and ODR for header definitions, not a guarantee of inlining, class members, inline variables (C++17), and virtual functions.
-
C++ Exception Performance: Zero-Cost, noexcept, and Error
C++ exception model: zero-cost on success path, cost of throw and unwind, noexcept and vector moves, frequent errors vs exceptions, and -fno-exceptions.
-
C++ Cache Optimization: Locality, False Sharing, SoA vs AoS
Improve CPU cache efficiency in C++: spatial locality, matrix layout, struct packing, prefetching, blocking, false sharing, and alignment for SIMD.
-
Two Pointers: Turning O(n²) Pair Searches into O(n), and Why It Works
The two pointers technique explained through why each move is safe: sorted pair sums, 3Sum, container with most water, in-place removal, and positive-only subarray sums, plus the input conditions each pattern silently depends on.
-
Sliding Window Technique: Fixed vs Variable Windows and When to Shrink
Sliding window algorithm optimizes fixed and variable-length contiguous ranges by sliding one position at a time in O(n).
-
Fixing TLE: Reading Constraints and Cutting Time Complexity in Coding Interviews
How to read N and Q to pick a target complexity, spot hidden O(N) steps inside loops, and replace nested loops with sorting, hashing, prefix sums or windows.
-
Greedy Algorithms: When the Locally Best Choice Works and How to Prove It
Why greedy works for interval scheduling and fractional knapsack but fails for coins {1,3,4} and 0/1 knapsack: exchange arguments, counterexamples, stress tests.
-
Algorithm Optimization Case Studies
Real-world case studies of solving TLE in competitive programming. Learn optimization techniques to improve from O(n²) to O(n log n), and O(n³) to O(n).
-
The Flyweight Pattern in C++: Sharing Intrinsic State to Cut Memory in Text and Tile Maps
Flyweight in C++: split shared intrinsic state from per-object extrinsic state, with glyph, font and tile-map examples and the mutation and cache-growth traps.
-
Expression Templates in C++: Lazy Evaluation That Removes Temporaries in Vector and Matrix Math
Expression templates in C++: building lazily evaluated expression trees to eliminate temporaries in vector and matrix operations, with a small math library and benchmarks.
-
Speeding Up Turborepo Builds: Cache Outputs, Task Graph, Remote Cache and Filtering
How to make Turborepo builds faster in practice: correct outputs and inputs, a lean task graph, environment variables in the cache key, Remote Cache, and running only affected packages in CI. Uses Turborepo 2.x turbo.json syntax.