Skip to main content

Performance Optimization

As a software engineer, I've found that ensuring applications run efficiently under various conditions is crucial. Here are some notes on strategies and techniques for optimizing software performance that I've found useful throughout my career.

Code Optimization

Writing cleaner and more efficient code is always a goal:

  • Refactoring: Keeping the code simple and removing unnecessary complexity.
  • Asynchronous programming: Using async and await to prevent blocking operations, especially I/O operations.
  • Memory management: I try to manage resources wisely, avoiding memory leaks by disposing of unnecessary objects.

Monitoring and Profiling

I keep a regular check on my applications to identify performance bottlenecks through monitoring and profiling tools:

  • Using tools like New Relic or Datadog: These tools help me monitor the applications in real-time.
  • Profiling sessions: They are crucial for understanding which functions or operations take up the most time.

Here is to more about this section Monitoring and Logging tools.

Caching

Caching is a lifesaver when it comes to enhancing performance. It's all about storing parts of data so that future requests for that data can be served faster. Here's how I use caching:

  • Client-side caching: Keeps data right on the user’s device. Super handy for reducing network calls.
  • Server-side caching: Saves data on the server to avoid hitting the database for every request.
  • CDNs (Content Delivery Networks): These are great for caching static resources near users to improve load times massively.

Tools I've used:

  1. Client-side caching with Redis

Database Optimization

Efficiently managing the database can make a big difference:

  • Indexing: This is crucial. Indexes help speed up data retrieval and can make queries much faster.
  • Query optimization: I spend time ensuring my queries are as efficient as possible, avoiding fetching unnecessary data.

Load Balancing

Using a load balancer to distribute incoming traffic across multiple servers has been crucial:

  • Decreases the burden on any single server, and provides redundancy, which is great for application availability and reliability.
  • Efficiently allocates requests to servers based on current load, optimizing resource use and maximizing throughput.

One of the best technology I've used to implement load balancing:

  1. Nginx

Resource Minimization

Minimizing the size of the resources that need to be loaded is key:

  • Minify resources: I minify JavaScript, CSS, and HTML to reduce their size which improves load times.
  • Optimize images: Compressing images without losing quality helps a lot.

One of the best practices to implement resource minimization is to use webpack or bundler like Webpack or Turbopack.

Front-end Optimization

The front end is where users interact with my app, so it’s got to be really fast:

  • Critical rendering path: I ensure the most important content loads first, so users can start interacting with the app as soon as possible.
  • Lazy loading: I delay loading certain parts of the page until they're actually needed, which is great for long web pages with lots of images.

Here is to more about this section Rendering Strategy.

Check out these cool articles about performance:

  1. Composite metrics for measure performance
  2. FE Latency Numbers by Vercel CTO
  3. Speeding up File Load Times
  4. Bundle Size Analyzer by Grab
  5. WebAssembly at Figma
  6. Why Speed Matters
  7. Shopping for Speed @ Ebay
  8. Speed By A Thousand Cuts
  9. Making Instagram.com faster: Part 1
  10. Making Instagram.com faster: Part 2
  11. Making Instagram.com faster: Part 3 — cache first
  12. Twitter Lite and High Performance React Progressive Web Apps at Scale
  13. How we sped up Notion in the browser with WASM SQLite
  1. Effective Performance Engineering at Twitter-Scale

Nice References

  1. Refactoring
    1. Refactoring Guru
  2. Asynchronous Programming
    1. Asynchronous by Mozilla
    2. Asynchronous by MSFT
  3. Coroutines
    1. Kotlin Coroutines
    2. Kotlin Coroutines in Android
  4. Golang concurrency
    1. Effective Go Docs
  5. Frontend Optimization with Rendering
    1. ReactJS Rendering Patterns

Tools

  1. Web:
    1. Lighthouse