perf: eliminate high CPU/GPU load, remove smooth cursor, remove canvas particles, throttle scroll handler

This commit is contained in:
Vaishno Singh
2026-11-07 02:25:00 +05:30
parent 58056f39f1
commit 4441c3aee3
4 changed files with 35 additions and 37 deletions
@@ -74,13 +74,12 @@ export function CinematicHorizontalScrollSection({
const translateX = progress * maxDistance;
track.style.transform = `translate3d(-${translateX.toFixed(2)}px, 0, 0)`;
// Sync active card index and button states
// Sync active card index and button states — batched into one setState call
const active = Math.min(
cards.length - 1,
Math.max(0, Math.round(progress * (cards.length - 1)))
);
setActiveIndex(active);
setCanScrollLeft(progress > 0.02);
setCanScrollRight(progress < 0.98);
}, []);
@@ -88,8 +87,15 @@ export function CinematicHorizontalScrollSection({
useEffect(() => {
const container = containerRef.current;
// RAF-throttled scroll handler: fires at most once per animation frame (≤60/s)
// preventing the expensive DOM reads from firing hundreds of times per second.
let rafId: number | null = null;
const handleScroll = () => {
updateTranslation();
if (rafId !== null) return;
rafId = requestAnimationFrame(() => {
updateTranslation();
rafId = null;
});
};
// Support horizontal trackpad swipe (deltaX) on the showcase container
@@ -136,6 +142,7 @@ export function CinematicHorizontalScrollSection({
}
return () => {
if (rafId !== null) cancelAnimationFrame(rafId);
window.removeEventListener('scroll', handleScroll);
window.removeEventListener('resize', handleScroll);
if (container) {
@@ -260,7 +267,7 @@ export function CinematicHorizontalScrollSection({
{/* Horizontal Track */}
<div
ref={trackRef}
className="cinematic-rail flex gap-6 will-change-transform"
className="cinematic-rail flex gap-6"
style={{
paddingLeft: 'calc((100vw - min(780px, 88vw)) / 2)',
paddingRight: 'calc((100vw - min(780px, 88vw)) / 2)',