Skip to content
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

Merged
merged 3 commits into from Apr 26, 2023
Merged

feat: minor code enhancements #48

merged 3 commits into from Apr 26, 2023

Conversation

scr2em
Copy link
Contributor

@scr2em scr2em commented Apr 25, 2023

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

Copy link
Owner

@yoavbls yoavbls left a 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

@@ -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");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

codeSplit -> codeLines

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);
Copy link
Owner

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

Copy link
Contributor Author

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.

Copy link
Owner

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yoavbls done

Copy link

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.

Copy link
Contributor Author

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

Copy link

@rchl rchl Apr 25, 2023

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.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're probably right. We have to find a way to do fewer replacements like this and invoke prettier just when it's necessary.
@rchl @scr2em any help in measuring and solving this problem will be appreciated 🙏🏼

Copy link
Owner

@yoavbls yoavbls left a 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

Copy link
Owner

@yoavbls yoavbls left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@yoavbls yoavbls merged commit fed2989 into yoavbls:main Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants