iafisher / drill

Spaced-repetition quizzes on the command line
MIT License
2 stars 0 forks source link

Parsing quizzes with many custom scripts is slow #88

Closed iafisher closed 4 years ago

iafisher commented 4 years ago

Two ideas

  1. Somehow avoid spawning the script for each question by adjusting the protocol so that the script is spawned once for the whole quiz.
  2. Run the scripts lazily, e.g. after a question is selected to be in the quiz (since most questions don't make it into the quiz) or just before it is asked.
iafisher commented 4 years ago

Option 2 isn't good because if the script or question has an error, the user won't find out until the middle of the quiz.

iafisher commented 4 years ago

When I replaced the Python script with a simple C stand-in, parsing was almost instantaneous again, which indicates that one possible solution is just writing faster scripts.

iafisher commented 4 years ago

Option 2 also wouldn't speed up runs that do require parsing every question, like the count subcommand.

iafisher commented 4 years ago

Expanding on option 1: add a new server-script tag so that it's opt-in. The quiz parser spawns the script the first time it is encountered and keeps it running for the duration of parsing. For each question, it writes the two or more lines to the script's standard input: the text of the question, zero or more lines of answers, and some end-of-message line (e.g., END, but probably something less generic so there's no risk of it coinciding with an actual answer). For each question, the script should respond the same way as in the old protocol. Finally, the parser will write END_OF_QUIZ or something to shut the process down.

iafisher commented 4 years ago

Solution: re-write the slow script in a faster language, like Rust.