Development

Mobile App Performance: Optimization Techniques

December 15, 2024
7 min read
Abdullah Kabli

Mobile App Performance: Optimization Techniques

In the competitive Saudi app market, performance isn't just a feature—it's a dealbreaker. Users expect apps to load in under 2 seconds, and 53% will abandon an app that takes longer than 3 seconds to load.

This guide covers the essential performance optimization techniques we use at ATK to build fast, responsive mobile apps.

Why Performance Matters in Saudi Arabia

Network Conditions
While Saudi Arabia has excellent 4G/5G coverage in cities, many users still experience:
- Variable network speeds in rural areas
- High latency during peak hours
- Limited bandwidth in crowded areas

Device Diversity
The Saudi market includes:
- High-end: iPhone 15 Pro, Samsung S24 Ultra
- Mid-range: iPhone 12, Samsung A54
- Budget: Xiaomi, Realme devices

Your app must perform well across all tiers.

User Expectations
Saudi users are sophisticated and have zero tolerance for:
- Slow load times
- Laggy animations
- Battery drain
- Excessive data usage

Performance Metrics That Matter

Core Web Vitals (for Web Apps)
1. LCP (Largest Contentful Paint): < 2.5s
2. FID (First Input Delay): < 100ms
3. CLS (Cumulative Layout Shift): < 0.1

Mobile-Specific Metrics
1. App Launch Time: < 2s cold start
2. Time to Interactive: < 3s
3. Frame Rate: Consistent 60fps
4. Memory Usage: < 200MB for basic apps
5. Battery Impact: < 5% per hour of active use

Optimization Techniques

1. Image Optimization

Problem: Images account for 60%+ of app size and load time.

Solutions:
- Use WebP format: 25-35% smaller than JPEG
- Lazy loading: Load images as needed
- Responsive images: Serve appropriate sizes
- CDN delivery: Use CloudFlare or AWS CloudFront
- Compression: TinyPNG, ImageOptim

Code Example (React Native):
```javascript
import FastImage from 'react-native-fast-image';

style={styles.image}
source={{
uri: 'https://cdn.example.com/image.webp',
priority: FastImage.priority.normal,
}}
resizeMode={FastImage.resizeMode.cover}
/>
```

2. Code Splitting & Lazy Loading

Problem: Loading entire app on startup is slow.

Solutions:
- Route-based splitting: Load screens on demand
- Component lazy loading: Import heavy components dynamically
- Tree shaking: Remove unused code

Code Example (Next.js):
```typescript
import dynamic from 'next/dynamic';

const HeavyComponent = dynamic(() => import('./HeavyComponent'), {
loading: () => ,
ssr: false
});
```

3. API Optimization

Problem: Slow API calls block the UI.

Solutions:
- Pagination: Load data in chunks
- Caching: Store frequently accessed data
- Debouncing: Limit API calls on user input
- Parallel requests: Fetch independent data simultaneously
- GraphQL: Request only needed fields

Code Example (React Query):
```typescript
import { useQuery } from '@tanstack/react-query';

const { data, isLoading } = useQuery({
queryKey: ['products'],
queryFn: fetchProducts,
staleTime: 5 * 60 * 1000, // 5 minutes
cacheTime: 10 * 60 * 1000, // 10 minutes
});
```

4. Database Optimization

Problem: Slow database queries impact performance.

Solutions:
- Indexing: Add indexes on frequently queried fields
- Query optimization: Use EXPLAIN to analyze queries
- Connection pooling: Reuse database connections
- Read replicas: Separate read/write operations

Example (Supabase):
```typescript
// Add index
await supabase.rpc('create_index', {
table_name: 'products',
column_name: 'category_id'
});

// Optimized query
const { data } = await supabase
.from('products')
.select('id, name, price')
.eq('category_id', categoryId)
.limit(20);
```

5. Memory Management

Problem: Memory leaks cause crashes and slowdowns.

Solutions:
- Clean up listeners: Remove event listeners on unmount
- Cancel requests: Abort pending API calls
- Limit list size: Use virtualized lists
- Optimize images: Release unused image memory

Code Example (React Native):
```typescript
useEffect(() => {
const subscription = eventEmitter.addListener('event', handler);

return () => {
subscription.remove(); // Cleanup
};
}, []);
```

6. Animation Performance

Problem: Janky animations hurt UX.

Solutions:
- Use native driver: Offload animations to native thread
- Avoid layout animations: Use transform instead
- Optimize re-renders: Use React.memo, useMemo
- Reduce animation complexity: Simplify paths and effects

Code Example (React Native Animated):
```typescript
Animated.timing(fadeAnim, {
toValue: 1,
duration: 300,
useNativeDriver: true, // ✅ Offload to native
}).start();
```

7. Bundle Size Optimization

Problem: Large app bundles slow downloads and updates.

Solutions:
- Remove unused dependencies: Audit with webpack-bundle-analyzer
- Use lighter alternatives: date-fns instead of moment.js
- Code splitting: Split by route or feature
- Minification: Use Terser for production builds

Stats:
- Target: < 10MB for iOS, < 15MB for Android
- Acceptable: < 20MB
- Too large: > 30MB

8. Network Optimization

Problem: Slow network requests hurt performance.

Solutions:
- HTTP/2: Enable multiplexing
- Compression: Enable gzip/brotli
- Prefetching: Load next screen data early
- Offline support: Cache critical data locally
- Request batching: Combine multiple API calls

Code Example (Axios):
```typescript
const api = axios.create({
baseURL: 'https://api.example.com',
timeout: 10000,
headers: {
'Accept-Encoding': 'gzip, deflate, br'
}
});
```

Performance Monitoring

Tools We Use

1. React Native Performance Monitor
- Built-in FPS meter
- Memory usage tracking
- JS thread monitoring

2. Firebase Performance Monitoring
- Real-time metrics
- Network request tracking
- Custom traces

3. Sentry
- Error tracking
- Performance monitoring
- Release health

4. New Relic Mobile
- Crash analytics
- Network insights
- User journey tracking

Key Metrics to Track

1. App Start Time: Cold vs warm start
2. Screen Load Time: Per screen average
3. API Response Time: P50, P95, P99
4. Crash-Free Rate: Target > 99.5%
5. ANR Rate: Target < 0.1%

Performance Testing

Load Testing
- Tool: Artillery, k6
- Test: 1000+ concurrent users
- Goal: < 500ms response time

Stress Testing
- Tool: JMeter
- Test: Gradual load increase
- Goal: Identify breaking point

Device Testing
- Real devices: Test on 5+ devices
- Emulators: Quick iteration
- Cloud testing: BrowserStack, Sauce Labs

Saudi-Specific Optimizations

1. Arabic Font Optimization
- Use system fonts when possible
- Subset custom fonts
- Preload critical fonts

2. RTL Layout Performance
- Use Flexbox (not absolute positioning)
- Test RTL-specific animations
- Optimize bidirectional text rendering

3. Local CDN
- Use Middle East CDN regions
- Cache static assets regionally
- Reduce latency for Saudi users

4. Prayer Times Integration
- Cache prayer times locally
- Update once daily
- Minimal battery impact

Performance Checklist

Before launching your app:

Images
- [ ] All images compressed
- [ ] WebP format used
- [ ] Lazy loading implemented
- [ ] CDN configured

Code
- [ ] Bundle size < 20MB
- [ ] Code splitting enabled
- [ ] Tree shaking configured
- [ ] Minification enabled

API
- [ ] Caching implemented
- [ ] Pagination added
- [ ] Error handling robust
- [ ] Timeout configured

Monitoring
- [ ] Performance monitoring setup
- [ ] Error tracking enabled
- [ ] Analytics configured
- [ ] Alerts configured

ATK's Performance Standards

At ATK, we guarantee:
- < 2s app launch time
- 60fps smooth animations
- < 200MB memory usage
- 99.5%+ crash-free rate

Need help optimizing your app? [Let's talk](https://atkabli.com/en/contact).

---

ATK — Licensed Freelance Product Studio
Building fast, responsive apps for Saudi users.

Ready to Build Your Product?

Let's discuss your project and turn your vision into reality.