performance

typescript
import { useState } from 'react'
import { useQuery } from '@tanstack/react-query'
import { useDebounce } from '@/hooks/useDebounce'
import api from '@/services/api'

export function SearchInput() {

Debounced search with controlled inputs

react search debounce
by Maya Patel 1 tab
javascript
class BatchLoader {
  constructor(batchFn, { cacheKeyFn = (k) => k } = {}) {
    this.batchFn = batchFn;
    this.cacheKeyFn = cacheKeyFn;
    this.cache = new Map();
    this.queue = [];

Coalescing Concurrent Reads with a DataLoader-Style Batch Loader in Node

dataloader batching graphql
by codesnips 3 tabs
typescript
import { memo } from 'react'
import { Post } from '@/types'

interface PostListItemProps {
  post: Post
  onLike: (id: string) => void

React memo for component optimization

react performance optimization
by Maya Patel 2 tabs
ruby
class ArticlesController < ApplicationController
  def index
    # Bounded queries: without preload, article.author in the view raises.
    @articles = Article
      .published
      .preload(:author, :tags)

Strict Loading to Catch N+1 in Development

rails activerecord performance
by codesnips 4 tabs
ruby
class Product < ApplicationRecord
  has_many :reviews, dependent: :destroy

  scope :published, -> { where(published: true) }

  def average_rating

Russian Doll Fragment Caching with Touch Propagation in Rails

rails caching fragment-caching
by codesnips 4 tabs
rust
#![feature(asm)]

fn add_asm(a: u64, b: u64) -> u64 {
    let result: u64;
    unsafe {
        asm!(

Inline assembly for critical performance hotspots

rust assembly performance
by Marcus Chen 1 tab
yaml
production:
  adapter: postgresql
  encoding: unicode
  pool: <%= ENV.fetch("RAILS_MAX_THREADS", 5) %>
  timeout: 5000
  checkout_timeout: 5

Database connection pooling configuration

rails database performance
by Alex Kumar 2 tabs
python
import functools
import threading
import time
from collections import OrderedDict

Custom TTL + LRU Cache Decorator for Expensive Python Computations

python caching lru
by codesnips 2 tabs
javascript
import { useEffect, useState } from "react";

export function useDebounce(value, delay = 300) {
  const [debounced, setDebounced] = useState(value);

  useEffect(() => {

Debounced Search Box With Live Autocomplete in React

react hooks debounce
by codesnips 3 tabs