performance enhancements#47
Conversation
30a727c to
5170b03
Compare
|
thanks for the PR @jdalton , i'll be sure to go over it soon |
67ed86f to
acf1b4d
Compare
|
@nirgit I updated it to keep the source readable and inline during build. I've added a way to annotate what is inlined. It allows for fine grain control and seems to be working well. |
a6aef3c to
3be9669
Compare
i'll try to go over the PR in the upcoming week. |
e31a822 to
c8cd0d4
Compare
0fd1c66 to
062161b
Compare
bd2488e to
0cc4a79
Compare
nirgit
left a comment
There was a problem hiding this comment.
big PR.
i'd rather having this PR separated into several smaller PRs so its easier to review.
for instance:
- PR for converting everything to constants
- PR for refactoring the lexer
- PR for refactoring the parser
that way it'd be a whole lot easier to track, sorry.
i did not finish reviewing everything, and still need to go over the parser.js part and the astToJson.js, but since there are already some comments, i thought i'd already send those in so you can have a look, and we'll take it from there.
thanks
|
|
||
| const { readXMLFile } = require('./testUtils') | ||
| const { convertXML } = require('../src/xmlToJson') | ||
| const { convertXML } = require('../lib/simpleXmlToJson.min.js') |
There was a problem hiding this comment.
cool, but this means that running npm test cannot happen without running npm run build. pls fix
There was a problem hiding this comment.
I can make it build before tests are run :)
| const iterations = 4000 | ||
| for (let i = 0; i < iterations; i += 1) { |
There was a problem hiding this comment.
why all this hassle? why not just rename transpiler.js to parser.js :)?
There was a problem hiding this comment.
any changes here?
if there aren't any, lets just do a rename for transpiler.js to parser.js?
| const Token = (type, value) => ({ | ||
| type, | ||
| value | ||
| const Token = ($type, $value = '') => ({ |
There was a problem hiding this comment.
Inlining vars is easier when they aren't shortcut properties.
| let peekedPos = 0 | ||
| let peekedTagName = '' |
| const isCharBlank = (char) => | ||
| char === ' ' || char === '\n' || char === '\r' || char === '\t' | ||
| function createLexer(xmlAsString, { knownAttrib, knownElement } = {}) { | ||
| const { length } = xmlAsString |
There was a problem hiding this comment.
pls check if xmlAsString is null or undefined
| const scoping = [] | ||
| let currScope = 0 | ||
| let currToken = EOF_TOKEN | ||
| let currTokenType = TOKEN_TYPE.EOF |
There was a problem hiding this comment.
why do we need this if we have currToken? we can just check currToken.type
There was a problem hiding this comment.
We will for another biggie optimization after (accepting known elements and known attributes and skipping object creation and string slicing for those skipped).
| (code >= CHAR_CODE.DIGIT_0 && code <= CHAR_CODE.DIGIT_9) || | ||
| code === CHAR_CODE.LODASH || | ||
| code === CHAR_CODE.COLON || | ||
| code === CHAR_CODE.HYPHEN |
There was a problem hiding this comment.
i think period should also be included
|| code === CHAR_CODE.PERIOD
There was a problem hiding this comment.
tag names can only start with a letter or an underscore.
so its a problematic check to include numbers and other invalid chars in the same if.
There was a problem hiding this comment.
Good to know. Currently (master branch) does allow digits and other chars:
simple-xml-to-json/src/lexer.js
Line 93 in ec2e488
The inlining of the regexp reflects what is in master (more or less).
There was a problem hiding this comment.
| : Token( | ||
| /*inline*/ | ||
| TOKEN_TYPE.CONTENT, | ||
| buffer + | ||
| readAlphaNumericAndSpecialChars() | ||
| ) | ||
| return currToken |
There was a problem hiding this comment.
The 'should support textual content for elements', test passes on the jdalton/optimize branch.

I've optimized the lib:
Before for 4,000 iterations:
After for 4,000 iterations: