magic-string's trim method uses a regex check for aborting which turns
out to be extremely expensive - it cna take up to 10% time in total SFC
compilation! The usage here is purely aesthetic so simply removing it
for a big perf gain is well worth it.
Previously, many CodegenContext.push() calls were unnecessarily
iterating through the entire pushed string to find newlines, when we
already know the newline positions for most of calls. Providing fast
paths for these calls significantly improves codegen performance when
source map is needed.
In benchmarks, this PR improves full SFC compilation performance by ~6%.
functionaddMapping(loc: Position,name: string|null=null){// @ts-ignore we use the private property to directly add the mapping
// because the addMapping() implementation in source-map-js has a bunch of
// unnecessary arg and validation checks that are pure overhead in our case.
const{_names,_mappings}=context.mapif(name!==null&&!_names.has(name))_names.add(name)_mappings.add({originalLine: loc.line,originalColumn: loc.column-1,// source-map column is 0 based
generatedLine: context.line,generatedColumn: context.column-1,source: filename,name})}// ....
}