npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

nextjs-memory-profiler

v1.0.1

Published

Memory leak detection and profiling tool for Next.js applications

Downloads

20

Readme

nextjs-memory-profiler

Next.js uygulamalarında memory leak tespiti ve memory profiling için geliştirilmiş bir araç.

Kurulum

npm install nextjs-memory-profiler

Hızlı Başlangıç

Next.js uygulamanızda memory leak tespiti için iki farklı yaklaşım kullanabilirsiniz:

1. Middleware ile Kullanım

middleware.ts dosyanızda:

import MemoryProfiler from 'nextjs-memory-profiler';

const profiler = new MemoryProfiler({
  threshold: 50, // 50MB üzeri artışlarda uyarı ver
});

// Profiler'ı başlat
profiler.start();

export function middleware(request) {
  // Route profiling başlat
  const routeProfiler = profiler.startRouteProfiler(request.nextUrl.pathname);

  // Response tamamlandığında
  request.nextUrl.searchParams.forEach(() => {
    // Profiling'i sonlandır
    routeProfiler.end();
  });
}

2. Sayfa Bileşeni ile Kullanım

Herhangi bir page component'inizde:

'use client';

import { useEffect } from 'react';
import MemoryProfiler from 'nextjs-memory-profiler';

const profiler = new MemoryProfiler({
  threshold: 50
});

export default function Page({ params }) {
  useEffect(() => {
    // Route profiling başlat
    const routeProfiler = profiler.startRouteProfiler(`/pages/${params.slug}`);

    // Component unmount olduğunda profiling'i sonlandır
    return () => {
      routeProfiler.end();
    };
  }, [params.slug]);

  return <div>{/* Sayfa içeriği */}</div>;
}

Raporlar ve Çıktılar

Profiler iki tür çıktı üretir:

  1. memory-profile.log:

    • Anlık uyarılar
    • Memory leak tespitleri
    • Yüksek memory kullanım uyarıları
  2. memory-report.json:

    • Route bazlı analiz
    • Memory kullanım trendleri
    • Her route için:
      • Toplam istek sayısı
      • Ortalama memory kullanımı
      • İşlem süreleri
      • Memory artış/azalış trendi

Konfigürasyon

const profiler = new MemoryProfiler({
  interval: 5000,    // Memory ölçüm aralığı (ms)
  threshold: 50      // Memory leak uyarı eşiği (MB)
});

| Seçenek | Açıklama | Varsayılan | |---------|-----------|------------| | interval | Ölçüm aralığı (ms) | 5000 | | threshold | Memory artış eşiği (MB) | 100 |

Memory Leak Tespiti

Profiler şu durumlarda uyarı verir:

  1. Route Bazlı Memory Leak:

    • Aynı route'a yapılan ardışık isteklerde memory kullanımı eşik değerini aşarsa
  2. Genel Memory Kullanımı:

    • Toplam heap kullanımı limit değerinin %80'ini aşarsa
    • Belirli bir süre içinde anormal memory artışı tespit edilirse

Performans İzleme

Her route için şu metrikler izlenir:

  • Memory kullanımı (MB)
  • İşlem süresi (ms)
  • Memory kullanım trendi
  • Maksimum ve minimum memory kullanımı

Önemli Notlar

  1. Server-Side Kullanım:

    • Bu paket sadece server-side'da çalışır
    • Client-side'da kullanılırsa uyarı verir ve işlem yapmaz
  2. Otomatik Temizlik:

    • Uygulama kapatıldığında (SIGINT/SIGTERM) profiler otomatik olarak durur
    • Son rapor otomatik olarak oluşturulur
  3. Hata Yönetimi:

    • Tüm kritik operasyonlar try-catch ile korunur
    • Hata durumunda uygun fallback değerler kullanılır

Hata Ayıklama

Memory leak tespit edildiğinde:

  1. memory-profile.log dosyasını kontrol edin
  2. Hangi route'da leak tespit edildiğini belirleyin
  3. İlgili route'un component'lerini ve data fetching logic'ini gözden geçirin
  4. Memory-report.json'daki trend analizini inceleyin

Lisans

MIT