From 9f8eab4a31e58b4dc77ba706238e7d8c005d2b65 Mon Sep 17 00:00:00 2001 From: Sterlen Date: Tue, 30 Dec 2025 08:17:34 -0600 Subject: [PATCH] perf: Offload XML parsing to a background isolate using `compute`. --- lib/services/bible_xml_parser.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/services/bible_xml_parser.dart b/lib/services/bible_xml_parser.dart index a5e7ab2..e5607bf 100644 --- a/lib/services/bible_xml_parser.dart +++ b/lib/services/bible_xml_parser.dart @@ -1,7 +1,13 @@ import 'package:flutter/services.dart' show rootBundle; +import 'package:flutter/foundation.dart'; import 'package:xml/xml.dart'; import '../models/scripture.dart'; // Assuming Scripture model might need BibleTranslation +// Helper for background XML parsing +XmlDocument parseXmlString(String xml) { + return XmlDocument.parse(xml); +} + class BibleXmlParser { // Map of common Bible book names to their standard abbreviations or keys used in XML // This will help in matching references like "Matthew 11:28" to XML structure. @@ -56,7 +62,7 @@ class BibleXmlParser { print('Loading and parsing XML asset: $assetPath'); // Debug log final String xmlString = await rootBundle.loadString(assetPath); - final document = XmlDocument.parse(xmlString); + final document = await compute(parseXmlString, xmlString); _xmlCache[assetPath] = document; return document; }