Performance & Security Quiz
Validate your understanding of optimisation and security fundamentals. Each question mirrors real trade-offs you will encounter on RubyDev.
Instructions: Pick the best answer, then review the explanation block. Focus on why an option is correct rather than memorising details.
1. Benchmarking
Which approach yields reliable micro-benchmark results?
B) Use Benchmark::IPS with warmed caches and `x.compare!`.
C) Profile in production without informing the team.
D) Swap code blindly and hope it is faster.
Answer: B — Benchmark::IPS runs statistically significant iterations and compares implementations.
2. GC tuning
Heap usage climbs steadily in Sidekiq. Which tactic helps confirm a memory leak?
B) Inspect `GC.stat(:heap_live_slots)` and capture heap dumps over time.
C) Disable GC entirely.
D) Reboot the worker after each job.
Answer: B — monitor heap growth and analyse dumps to spot leaked objects.
3. Caching
Your fragment cache serves stale content after lesson updates. What should you do?
B) Version cache keys with lesson timestamps and bust caches on updates.
C) Disable caching entirely.
D) Rely on users to hard refresh.
Answer: B — fingerprint cache keys so invalidation happens automatically.
4. Code injection
How do you safely call a formatter selected by the user?
B) `public_send(format, content)` without validation.
C) Whitelist allowed formatters, then call `public_send("render_#{format}", content)`.
D) Skip formatting entirely.
Answer: C — validate against a whitelist and dispatch only safe methods.
5. Secure storage
What is the correct way to store passwords?
B) Encrypted with reversible AES keys stored in code.
C) Hashed with BCrypt/Argon2 and salted; secrets managed externally.
D) Base64 encoded.
Answer: C — password hashing makes theft impractical; salts and secret management mitigate brute-force attacks.