performance

java
import com.github.benmanes.caffeine.cache.CacheLoader;
import com.github.benmanes.caffeine.cache.Caffeine;
import com.github.benmanes.caffeine.cache.LoadingCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

Time-Based Caffeine Cache for Expensive Currency Rate Lookups in Spring

caffeine caching spring
by codesnips 3 tabs
ruby
module Cacheable
  extend ActiveSupport::Concern

  def cache_query(prefix, scope, expires_in: 15.minutes)
    key = [prefix, cache_version_token(scope)].join("/")

Targeted Query Caching for Expensive Endpoints

rails activerecord performance
by codesnips 3 tabs
sql
-- Create materialized view
CREATE MATERIALIZED VIEW user_statistics AS
SELECT
  users.id,
  users.username,
  COUNT(DISTINCT orders.id) AS order_count,

Materialized views for performance optimization

postgresql materialized-views performance
by Maria Garcia 2 tabs
python
import functools
import threading


def debounce(wait):
    def decorator(func):

Debounce Repeated Function Calls With a Thread-Safe Python Decorator

python decorators debounce
by codesnips 2 tabs
typescript
import { createHash } from "crypto";
import { Request, Response } from "express";

export function computeEtag(body: string): string {
  const digest = createHash("sha1").update(body).digest("base64");
  return `"${digest}"`;

ETag + conditional GET for read-heavy endpoints

performance express http-caching
by codesnips 3 tabs
go
package export

import (
	"encoding/csv"
	"log"
	"net/http"

Streaming Large CSV Exports in Go Without Buffering the Whole File

go http csv
by codesnips 3 tabs
sql
-- Connection statistics
SELECT
  count(*) AS total_connections,
  count(*) FILTER (WHERE state = 'active') AS active,
  count(*) FILTER (WHERE state = 'idle') AS idle,
  count(*) FILTER (WHERE state = 'idle in transaction') AS idle_in_tx,

Database observability and monitoring metrics

database monitoring observability
by Maria Garcia 2 tabs
typescript
import { Suspense } from 'react'
import { useSuspenseQuery } from '@tanstack/react-query'
import { useParams } from 'react-router-dom'
import api from '@/services/api'
import { Post } from '@/types'
import { ErrorBoundary } from '@/components/ErrorBoundary'

React Suspense for data fetching

react suspense async-loading
by Maya Patel 1 tab
javascript
import React, { lazy, Suspense, useState, useEffect } from 'react';

// 1. Component lazy loading
const HeavyComponent = lazy(() => import('./HeavyComponent'));
const AdminPanel = lazy(() => import('./AdminPanel'));
const Dashboard = lazy(() => import('./Dashboard'));

Performance optimization - lazy loading and code splitting

performance optimization lazy-loading
by Alex Chang 2 tabs
sql
-- Basic EXPLAIN
EXPLAIN
SELECT * FROM users WHERE email = 'alice@example.com';

-- EXPLAIN with cost and row estimates
-- Output shows: Seq Scan on users (cost=0.00..15.50 rows=1 width=100)

EXPLAIN and query plan optimization

sql explain query-optimization
by Maria Garcia 2 tabs
python
from django.db.models import Prefetch
from django.views.generic import ListView
from .models import Post, Comment


class PostListView(ListView):

Django select_related and prefetch_related for N+1 query optimization

django python performance
by Priya Sharma 1 tab
ruby
class AddCommentsCountToPosts < ActiveRecord::Migration[6.1]
  def up
    add_column :posts, :comments_count, :integer, default: 0, null: false

    # Populate existing counts
    Post.find_each do |post|

Counter cache for association counts

rails performance activerecord
by Alex Kumar 2 tabs