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
feat: minor code enhancements #48
Conversation
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.
Thank you! 🙂
I left only minor comments
src/components/codeBlock.ts
Outdated
@@ -23,10 +23,11 @@ export const inlineCodeBlock = (code: string, language: string) => | |||
codeBlock(` ${code} `, language); | |||
|
|||
export const multiLineCodeBlock = (code: string, language: string) => { | |||
const maxLineChars = Math.max(...code.split("\n").map((line) => line.length)); | |||
const codeSplit = code.split("\n"); |
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.
codeSplit -> codeLines
src/components/codeBlock.ts
Outdated
const maxLineChars = Math.max(...code.split("\n").map((line) => line.length)); | ||
const codeSplit = code.split("\n"); | ||
|
||
const maxLineChars = codeSplit.reduce((acc,curr)=> curr.length > acc ? curr.length : acc, 0); |
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.
I prefer not to use reduce if possible.
In that case, I think it's less obvious to see that it's finding the maximum than Math.max
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.
@yoavbls I agree it's less obvious, but it saves you 2 loops and won't take as much memory as spreading an array in Math.max. I think any VScode plugin should focus on these small gains.
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.
It seems like a pre-mature optimization to me but since we didn't measure it and there is someone in the issues that feels performance impact by the extension I agree.
Can you just add a comment saying this line is finding the longest line please?
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.
@yoavbls done
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.
just after a brief look at the code I would guess that all the regexps have biggest performance impact. Caching them should likely improve things a lot.
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.
@rchl I'm looking now about how we can replace all these "replaceAll", this is the real bottleneck
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.
I think it's the whole point of this package to do "replace all" :)
But I think the performance would improve a lot if those regexps' wouldn't be recreated on every invocation of the function and instead would be created in global scope (if those are not dynamic) and reused in functions.
It should also help to combine regexes' to have less in total but that might not be feasible and it would probably make the code less readable.
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.
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.
I left a minor comment
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.
Thank you!
Hi, I love this extension.
I wanted to contribute this minor changes
1- 2 typo fixes
2- made TS error codes a set instead of an array
3- fixed an import