-
Notifications
You must be signed in to change notification settings - Fork 20
perf: flatten sourceMap to improve memory usage #4964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@@ -212,18 +211,26 @@ class YamlAstVisitor { | |||
return null; | |||
} | |||
|
|||
/* eslint-disable no-param-reassign */ | |||
private maybeAddSourceMap(node: unknown, element: Element): void { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
node: unknown - type with extends Node
from apidom-ast package
@@ -220,7 +206,14 @@ export const isPrimitiveElement: ElementPredicate<PrimitiveElement> = ( | |||
* @public | |||
*/ | |||
export const hasElementSourceMap = <T extends Element>(element: T): boolean => { | |||
return isSourceMapElement(element.meta.get('sourceMap')); | |||
return ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably using a Number.isInteger
is warranted here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And let's make this function safe - meaning it never throws. We can use isElement
and only continue after truthy assertion.
const sourceMapElement = element.getMetaProperty('sourceMap'); | ||
const charStart = toValue(sourceMapElement.positionStart.get(2)); | ||
const charEnd = toValue(sourceMapElement.positionEnd.get(2)); | ||
const charStart = element.startIndex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Align naming with new sourcemap fields.
} | ||
} | ||
if (hasElementSourceMap(from)) { | ||
to.startPositionRow = from.startPositionRow; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
assignSourceMap(to, from)
->
to.startPositionRow = from.startPositionRow
...
Possibly making it safe later. No parameter destricturing as it might be used in syntactic analysis or refracting, so we want to keep it fast.
return new JsonDocument({ | ||
children: node.children, | ||
position, | ||
startPositionRow: node.startPositionRow, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return new JsonDocument(
assignSourceMap({
children: node.children,
isMissing: node.isMissing,
}, node)
);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple of comments to look at, but the overall direction is LEGIT
No description provided.