perf: flatten sourceMap to improve memory usage#4964
Conversation
| } | ||
|
|
||
| /* eslint-disable no-param-reassign */ | ||
| private maybeAddSourceMap(node: unknown, element: Element): void { |
There was a problem hiding this comment.
node: unknown - type with extends Node from apidom-ast package
| */ | ||
| export const hasElementSourceMap = <T extends Element>(element: T): boolean => { | ||
| return isSourceMapElement(element.meta.get('sourceMap')); | ||
| return ( |
There was a problem hiding this comment.
Probably using a Number.isInteger is warranted here.
There was a problem hiding this comment.
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.
Align naming with new sourcemap fields.
| } | ||
| } | ||
| if (hasElementSourceMap(from)) { | ||
| to.startPositionRow = from.startPositionRow; |
There was a problem hiding this comment.
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.
return new JsonDocument(
assignSourceMap({
children: node.children,
isMissing: node.isMissing,
}, node)
);
char0n
left a comment
There was a problem hiding this comment.
Couple of comments to look at, but the overall direction is LEGIT
No description provided.