-
Notifications
You must be signed in to change notification settings - Fork 204
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
refactor(utils): replace with lodash #1694
Conversation
I think import from "lodash" with tree shaking also works (might need lodash-es). If you want to go this way you should add https://eslint.org/docs/rules/no-restricted-imports with "lodash". |
Without lodash-es it bundled the whole lodash package. |
Adding |
The problem is more likely the tsconfig module option. That should be set to ES and then webpack/esbuild should handle the conversion to cjs for the bundle. |
Good point. 👍 |
Looks like this will cause a 15-20% increase in the bundles size, which I consider reasonable considering Some of this increase will be nullified with the upcoming deprecation of features such as syntactic content assist. Might be worth looking into more ways to decrease the bundle size, although that is not the highest priority... |
Need to:
Edit:Object dictionary seems to have a slight performance advantage. |
@@ -0,0 +1,14 @@ | |||
export function PRINT_ERROR(msg: string) { |
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.
Can we just move these into the chevrotain package?
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 may be future utils that will be common/shared, so that gave me an incentive to keep the utils bundle.
- I believe the remaining three utils are all used in both the Parser and the Lexer, and I would like at some point in the future to extract the lexer to a separate package.
@@ -28,7 +28,7 @@ module.exports = { | |||
parserOptions: { | |||
// The `ecmaVersion` should align to the supported features of our target runtimes (browsers / nodejs / others) | |||
// Consult with: https://kangax.github.io/compat-table/es2016plus/ | |||
ecmaVersion: 2017 | |||
ecmaVersion: 2018 |
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.
this is a JS only option, for scripts / configuration which enables using ...
syntax
There is no proper benchmark for this, but it seems introducing lodash may have decreased the parser/lexer init time by ~10% |
@@ -203,7 +201,7 @@ export function buildAlternativesLookAheadFunc( | |||
}) | |||
return result | |||
}, | |||
[] | |||
{} as Record<number, number> |
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.
has in lodash on array assumes the array is non-holey and seems to use the length property.
Changing to an object dictionary seems to have very slightly improved performance as well.
WIP