IB Computer Science Translation: Compilers, Interpreters and JIT: Tutor Prep Guide (five stages, break-even, bytecode)
- 2026-11-27
Students agree that compilers are fast and interpreters are easy to debug, then cannot say after how many runs the compiler pays for itself. This lesson turns the choice into two sums: one translation cost against many execution costs, and one artefact against several platforms. With a break-even point the trade-off stops being a matter of taste.
01 Prerequisites (3-minute check)
If any of these fails, fix it before the lesson starts.
| Skill | Quick check | Pass mark |
|---|---|---|
| Machine code and source | What sits between machine code and a high level language | Assembly or an intermediate code |
| Division and ratio | Roughly what 36 divided by 8.8 is | Divides decimals to compare two totals |
| Fixed and variable cost | How to find where one option overtakes another | Divides the fixed cost by the per-run difference |
02 Lesson flow (60 minutes)
| Time | Stage | Tutor does | Student does |
|---|---|---|---|
| 0-8 min | Opening probe | Ask why the same loop must be compiled in C but not in Python | Write answers, compare at the end |
| 8-22 min | Two translators and five stages | Compile then run, against translate and run; one line per stage | Order the five stages |
| 22-36 min | Break-even and run counts | 0.8 seconds to compile, 0.14 seconds saved per run, break-even 5.71 | Compute and interpret the break-even |
| 36-46 min | Bytecode and JIT | One artefact on 3 platforms; JIT breaks even at 48.0 | Cost portability and JIT |
| 46-56 min | Error detection and scenarios | One build reports 12 errors; the interpreter stops at line 137 | Match three scenarios |
| 56-60 min | Exit check | Collect three questions, mark at once | Independent work |
03 Teaching script (read it out)
Scene 1: Two translators, where the difference is when you learn about errors, and how many at once
Teach the five stages as five actions, not five nouns. Lexical analysis cuts characters into tokens. Syntax analysis checks the order of tokens against a grammar and builds a parse tree. Semantic analysis checks types and declarations, which is where an undeclared variable is caught. Optimisation rewrites intermediate code, for example hoisting loop-invariant work out of a loop. Code generation emits target instructions. The first three stages exist to find errors, and the last two exist to make it fast.
Error detection is the sharpest difference. One compile can report all 12 syntax errors and no line has run. An interpreter stops at the first error, and in the worked example that is line 137, so 136 lines have genuinely executed, and if one of them wrote to a database the damage is done. So easy debugging means fast feedback, not safety, and the two must be said separately.
Close on portability as a count: one source, one compile per target platform, so the build work scales with the number of platforms.
Student task: write the five stages as five input and output sentences, then say which stage catches an undeclared variable and which catches a missing closing bracket.
Scene 2: Break-even, where compilers are fast becomes an inequality
The break-even is fixed cost over the per-run saving: 0.8 over the difference of 0.14 is 5.71, so from run 6 the compiled build has paid for its translation.
Run once and the interpreter wins by 4.67 times (0.84 seconds against 0.18). Run 200 times and the compiler wins by 4.09 times (8.8 seconds against 36.0). The same data reverses the answer, which is why students must compute both cases and why the question supplies a run count.
Now place bytecode. Source is translated once into platform independent bytecode, which a virtual machine executes. Bytecode is still interpreted statement by statement, so it is slower than machine code, but one translation runs anywhere a virtual machine exists.
Just-in-time compilation joins them: start interpreting bytecode while recording which methods are called repeatedly, then compile those hot methods to machine code and call them directly. The price is a warm-up of 1.2 seconds, so the break-even is 1.2 over the difference of 0.025, which is 48.0 runs, and at 500 runs the total falls from 30.0 to 18.7 seconds, 37.7 per cent less. That is why the same program starts slowly and speeds up: the start is translation, the speed later is machine code.
Student task: redo the break-even with a compile time of 2.4 seconds and explain why a long running server suits compilation while a one-off script suits interpretation.
Scene 3: Portability and scenarios, where one artefact against several platforms settles it
So the three scenarios are not preferences. Rapid development and testing need a short feedback loop, so interpret, because the break-even is never reached. Performance-critical work runs its inner loop millions of times, so the one-off compile cost is noise and a compiler wins. Cross-platform release of one application on computers and phones wants bytecode or JIT, translating once and running in many places.
Add two details that get examined. First, compilers are faster only once the run count passes the break-even. Second, interpreters are easier to debug only when the error appears early, because a fault deep in the run surfaces late, while a compiler reports a whole batch at once.
Finish by separating translation from execution. A compiled program knows nothing about its source at run time, so debugging relies on a symbol and line map. An interpreter reports line numbers in the source directly, which is the real reason its development experience is better.
Student task: for three projects (a marking tool a teacher edits ten times a day, a transaction core handling ten thousand records a second, a small game shipping on three platforms) choose a translator and justify it with a break-even or a platform count.
04 Question types and worked steps
| Type | Example | Steps | Answer |
|---|---|---|---|
| Compute a break-even and choose | 5,000 lines, 0.8 seconds to compile, 0.14 seconds saved per run, at 5 runs and at 500 | Fixed cost over the per-run saving, then compare with the run count | Break-even 5.71 runs; interpret at 5, compile at 500 |
| Order the stages and place an error | Six faults: missing bracket, undeclared variable, type mismatch, loop invariant, register pressure, misspelt keyword | Each stage owns one class of fault: lexical, syntax, semantic | Keyword in lexical, bracket in syntax, the rest in semantic |
| Cost portability | 3 platforms at 40 hours against one artefact at 6 hours | One side multiplies by platforms, the other adds test time | 120 hours against 6, 95.0 per cent less |
| Explain JIT behaviour (HL) | One program starts slowly and speeds up; 500 runs fall from 30.0 to 18.7 seconds | Find the hot path, compile it, and cost the warm-up against the per-run saving | Break-even 48.0 runs, 37.7 per cent less |
05 Independent practice (3 questions)
| Question | Answer | What to watch |
|---|---|---|
| 5,000 lines, 0.8 seconds to compile, 0.04 seconds per compiled run and 0.18 interpreted: how many runs to break even? | 5.71 runs, so from run 6 | Whether the fixed cost was divided by the per-run saving |
| Over 200 runs, what does each cost and by how much do they differ? | 8.8 seconds compiled against 36.0 interpreted, 4.09 times apart | Whether the single compile was included |
| 3 platforms at 120 hours, or one artefact at 6 hours: what percentage is saved? | 95.0 per cent | Whether the same side was used as the denominator |
06 Common mistakes and what to say
| Mistake | Student writes | Say this |
|---|---|---|
| Taking compiler speed as unconditional | Answering that compilers are always faster so everything should be compiled | “What is faster is execution, not development. On one run the compiler is 4.67 times slower and needs 5.71 runs to pay back the translation.” |
| Assuming an interpreter never runs the program | Writing that an interpreter only checks and never executes | “An interpreter translates and runs each statement. When the demo fails at line 137, the 136 lines before it have already done real work.” |
| Calling bytecode machine code | Answering that bytecode is machine code and therefore as fast | “Bytecode is a platform independent intermediate form interpreted by a virtual machine. Machine-code speed needs a JIT to compile the hot paths.” |
| Confusing JIT with ahead-of-time build | Writing that just-in-time compilation happens at install time | “JIT compiles while running, which is why start-up pays a warm-up. Building at install time is ahead-of-time compilation: fast start, less flexibility.” |
07 Homework (paper, section and question numbers)
- IB Computer Science chapter index — All chapters in this subject
- Operating systems, scheduling and control systems — The other chapter: nine functions, four schedulers, polling and deadlock
- Tutor prep guide index — Matching chapters in other subjects
08 Exit check (last 5 minutes)
| Question | Answer | Decision |
|---|---|---|
| Two translators | Compile then run, against translate and run | Cannot say when errors surface means replay act one |
| Break-even | Fixed cost over the per-run saving | Missing 5.71 runs means replay act two |
| Scenario choice | Interpret to develop, compile for speed, bytecode to ship | Answering only in fast and slow means replay act three |
09 Tutor FAQ
Must students memorise all five stages?
A1.4.1 asks for an evaluation of the process, so the split between checking up front and generating code at the back is enough, and stage names may follow the textbook. What matters is which stage catches which fault, and why a compiler reports several at once.
How far should JIT go?
IB names just-in-time compilation and bytecode interpreters explicitly, so hot-path compilation, warm-up cost and a break-even point are enough. Compilation thresholds and deoptimisation are extensions.
This chapter is HL only, so what do SL students need?
A1.4 is entirely HL, so SL students are not examined on it. They still meet compile time and run time errors when they code, so the classroom version can stop at which stage a fault belongs to.
Find a tutor — freeTutor Registration →
A TutorZone lesson-prep guide. Written by the TutorZone team; questions and lesson flow are original and are not taken from any school or publisher material.



