Some performance optimizations

This commit is contained in:
User user
2021-05-18 14:10:59 +02:00
parent 8e183ac1a5
commit 7ca0c4fd72
6 changed files with 5917 additions and 18 deletions

View File

@ -243,7 +243,8 @@ export class LoggingBase extends LoggingInterface {
}
const date = new Date();
const date_str = date.toISOString().replace(/T/, " ").replace(/\..+/, "");
const isoStr = date.toISOString();
const date_str = isoStr.substring(0, 10) + " " + isoStr.substring(11, 19);
let file: string | undefined = undefined;
if (this.#resolve_filename) {
@ -321,10 +322,12 @@ export class LoggingBase extends LoggingInterface {
let formattedMessage: Formatted<string>[] = [...linePrefix];
message.forEach((msg, idx) => {
let format = new Formatted();
let format: Formatted;
if (msg instanceof Formatted) {
format = msg;
msg = msg.content;
} else {
format = new Formatted();
}
if (typeof msg !== "string") {
@ -335,18 +338,17 @@ export class LoggingBase extends LoggingInterface {
}) as string;
}
removeColors(msg)
.split("\n")
.forEach((text, index, { length }) => {
if (index != length - 1) {
formattedMessage.push(
new Formatted(text + "\n", format),
...linePrefix
);
} else {
formattedMessage.push(new Formatted(text, format));
}
});
// removeColors(msg) // Remove colors is uncommented for now, since there are no real benefits of having it and it reduces performance
msg.split("\n").forEach((text, index, { length }) => {
if (index != length - 1) {
formattedMessage.push(
new Formatted(text + "\n", format),
...linePrefix
);
} else {
formattedMessage.push(new Formatted(text, format));
}
});
formattedMessage.push(new Formatted(" "));
});
@ -462,6 +464,7 @@ function getCallerFromExisting(err: Error): {
export function removeColors(text: string) {
text = text.replace(
// Putting regex here directly instead of externally actually improves performance. The cause of that is not clear for now.
/[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
""
);

View File

@ -203,7 +203,7 @@ export class DefaultFormatConfig implements FormatConfig {
date = new Formatted()._color(IColors.NONE);
file = new Formatted()._color(IColors.NONE);
names = new Formatted()._bold()._color(IColors.GREEN);
names = new Formatted()._bold()._color(IColors.CYAN);
names_delimiter = new Formatted(" -> ")._bold();
}