Ruby Logo

Performance & Security Quiz

Test your understanding of performance tuning and security hygiene for Ruby applications.

Home Ruby Performance & Security Quiz

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?

A) Run each implementation once and trust the output.
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?

A) Lower the GC threshold without measurements.
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?

A) Shorten TTLs drastically for all cache keys.
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?

A) `eval("render_#{format}")` on input.
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?

A) Plaintext in the database.
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.

Quick Navigation

Related Topics

Video Tutorial

Watch and learn performance & security quiz

Pro Tip: After reading through the content above, watch this video to reinforce your understanding and see the concepts in action!