Profiling a Dart CLI app

I had some trouble finding the docs for it, so I'll give you the right link:

There's a few gotchas. First you need to enable the Profiler after the app has launched. Second, if the app terminates, the Profiler closes as well. Because of that, I had to set up two break points and profile in this manner:

  1. Run the app in Debug mode.
  2. When the Debugger stops at the first breakpoint, activate the Profiler and hit Record.
  3. Resume the Run until you hit the second breakpoint.
  4. Stop the Profiler, but do not stop the Debugging.
  5. Analyze the results.
Once you hit the first breakpoint, Enable the Profiler and hit Record.
Verdict: I'm iterating in an XML with firstWhere and it is very costly. 4s to parse BookIndex. Total time: nearly 5s.
Iterating the BookIndex elements only once but still using firstWhere to find an enum. Down to 600 ms to parse BookIndex. Now the XML parsing from String takes more time: 850 ms. Total time: 1.5s.

Test after switching from firstWhere to a Map. Before:

factory Book.fromString(String code) =>
    Book.values.firstWhere((l) => l.code == code);


static Map<String, Book> _codeToBook =
    Map.fromEntries( => MapEntry(e.code, e)));

factory Book.fromString(String code) => _codeToBook[code]!;
Using a Map is not faster. If anything it's sometimes slower.

Perhaps the list is too short for Map to be faster. I'll keep the old version then.