Text content is appended one character at a time in parseXml
Maintainers usually reply within 4 days
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 56/100
- Issue type
- Feature
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js
- Domain
- backend, performance
Research direction
Start in src/xmlparser/OrderedObjParser.js at the parseXml text branch named in the issue. Compare the proposed indexOf and substring approach with the current loop, then run jasmine spec/*spec.js, including the text and preserveOrder cases described in the issue. Done means the specs pass and parsed output stays identical while text heavy input is processed in chunks.
Written by the indexing model from the issue text.
Description
Where
Why it's slow
In parseXml, every character that isn't part of a tag goes through the final else branch and is appended one at a time with textData += xmlData[i]. For documents with long text content (RSS/Atom feeds, articles, descriptions), most of the input goes through this path, so the parser does one loop iteration plus one string concat per text character.
Proposed fix
When the loop hits text, find the next < with indexOf, append the whole run with a single substring, and move i to just before that <. It still uses +=, so text split by a comment (<a>one<!--x-->two</a> -> "onetwo") is joined exactly as before. If there's no further <, the rest of the input is taken.
} else {
let nextTag = xmlData.indexOf('<', i);
if (nextTag === -1) nextTag = xmlLen;
textData += xmlData.substring(i, nextTag);
i = nextTag - 1;
}
Benchmark
Node 24.12, Apple M4 Pro. The machine was under load during the runs, so I used an in-process A/B: both versions loaded side by side, runs alternated, 31 timed rounds each, median ms per parse. Output was checked to be identical for every file/option pair. Numbers are from the second of two passes (the first pass was similar).
| Input | Options | before (ms) | after (ms) | speedup |
|---|---|---|---|---|
spec/assets/ptest.xml (1.3 KB) |
default | 0.013 | 0.012 | 1.08x |
preserveOrder |
0.010 | 0.009 | 1.10x | |
| text-heavy RSS (3 MB, ~800-char descriptions) | default | 40.6 | 25.4 | 1.60x |
ignoreAttributes: false |
71.0 | 42.4 | 1.67x | |
preserveOrder |
70.5 | 35.7 | 1.98x | |
| tag-dense (3 MB, short values) | default | 248.9 | 257.4 | 0.97x |
ignoreAttributes: false |
268.4 | 270.3 | 0.99x | |
preserveOrder |
173.4 | 174.4 | 0.99x |
node benchmark/XmlParser.mjs (on ptest.xml) also went up for fxp and fxp - preserve order in every before/after pair, but run-to-run noise on this machine was too high for its absolute numbers to be useful. Tag-dense input is about the same, within noise.
Tests
On the prototype branch, all 342 specs pass (jasmine spec/*spec.js), including two new ones in spec/data_spec.js: text split by comments, a long text run with entities, and text order with preserveOrder. Branch: https://github.com/TheNetherWatcher/fast-xml-parser/tree/perf/text-chunk
Happy to open a PR with this change if it seems useful/viable.
- Dominant language
- JavaScript
- Stars
- 3.1k
- Forks
- 410
- Avg merge
- 4d 15h
- Merged PRs (30d)
- 8
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from NaturalIntelligence/fast-xml-parser
-
A processing instruction with no target passes validation, then the builder prints invalid XMLPossibly taken @bardrop claimed this 1 day ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
NaturalIntelligence/fast-xml-parser#927 · 2 comments ·
Maintainers usually reply within 4 days
-
XMLValidator accepts double hyphens inside commentsPossibly taken @Sskift claimed this 16 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
NaturalIntelligence/fast-xml-parser#903 · 3 comments ·
Maintainers usually reply within 4 days
-
XMLValidator accepts raw < and & in attribute valuesPossibly taken @jeromeyyy claimed this 14 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
NaturalIntelligence/fast-xml-parser#900 · 3 comments ·
Maintainers usually reply within 4 days
-
getMetaDataSymbol() declares a boxed SymbolPossibly taken @chiragbitoni claimed this 4 days ago. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 comment ·
Maintainers usually reply within 4 days
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
NaturalIntelligence/fast-xml-parser#888 · 2 comments ·
Maintainers usually reply within 4 days
All issues in NaturalIntelligence/fast-xml-parser
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
-
Extended search drops any query term that contains a line breakPossibly taken @goranai claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day