This content originally appeared on DEV Community and was authored by Ahmed Rakan
I’ve been maintaining a library for my own SaaS that handles role-based access control (RBAC) on both the client and server side. It worked well, but I wanted to push its performance even further. Specifically, I was aiming for:
- Faster permission checks – Moving from linear scans to bit-level operations
- More efficient memory usage – From O(n) arrays to O(1) bitmaps
- Better performance overall, especially under heavy load
What Edge Computing Taught Me
Working with edge computing completely reshaped how I think about performance. Here are a few things that really stuck:
- Memory is limited – You have to cache smartly and keep your footprint small
- Data proximity matters – Optimize for fast, local lookups
- Predictability is key – Avoid operations that vary in execution time
The Optimization: Enter Bitmaps
Permission Checks Now ~10x Faster
-
Before: Looping through arrays to check permissions (
O(n)
) -
After: Bitwise lookups in constant time (
O(1)
)
// Old approach: linear scan
if (policy.can.includes("read")) { ... }
// New approach: bitwise check
const bitIndex = resourceIndex * numActions + actionIndex;
if (permissionBitmap.get(bitIndex)) { ... }
Slimmer, Faster Memory Use
- Before: Policy JSON with redundant strings everywhere
- After: Just 1 bit per permission—32x more compact than using booleans
// Packs 32 permissions into 4 bytes
const bitmap = new Uint32Array(Math.ceil(totalPermissions / 32));
Why This Matters
Super fast checks – Bitwise operations are CPU candy
Tiny memory footprint – 1 bit vs 8 bytes per permission
Cache-friendly – Hot data stays close in L1/L2
Backward compatible – Still supports the old method if needed
What I Learned
- Data locality is everything – Chasing pointers costs time
- Bits are powerful – Use them, CPUs love it
- Constraints = creativity – Edge forced me to optimize, and it paid off
End result? The library now handles 1,000+ requests per millisecond while barely touching memory.
Big takeaway: Working within constraints made me think differently—and code better. Edge computing didn’t just change my infrastructure, it changed how I approach performance.
Try the optimized library ^1.9.2 | See benchmarks
Curious—have constraints ever forced you to rethink your code? Let me know!
Best,
Ahmed,
This content originally appeared on DEV Community and was authored by Ahmed Rakan