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: do not serialize functions or constructors that are not invoked. #8

Merged
merged 8 commits into from Jun 22, 2022

Conversation

thantos
Copy link
Collaborator

@thantos thantos commented Jun 22, 2022

class C {
   static S = "x"
   constructor() {}
}
() => {
   // does not need the whole class
   C.S
}
() => {
   // needs the whole class
   new C()
}
() => {
   // needs the whole class
   C.S
   new C();
}
() => {
   // needs the whole class
   const doSomething = (d: any) => {}
   doSomething(C);
}

@thantos thantos requested a review from sam-goodwin June 22, 2022 01:10
Copy link
Contributor

@sam-goodwin sam-goodwin left a comment

Choose a reason for hiding this comment

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

Great job.

@@ -635,10 +642,11 @@ async function analyzeFunctionInfoAsync(
logInfo
);

// try to only serialize out the properties that were used by the user's code.
// try to only serialize out the pro perties that were used by the user's code.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: typo

capturedObjectProperties &&
capturedObjectProperties.length > 0
) {
entry.object = entry.object || { env: new Map() };
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you mean to use ?? instead of ||?

Copy link
Contributor

Choose a reason for hiding this comment

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

Why new Map()?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I copies this from elsewhere in the code, lol, but it appears that object needs to be a map or else things start to fail.

serialize,
logInfo
);
// if not invoked, let the property be treated like an object
Copy link
Contributor

Choose a reason for hiding this comment

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

meaning attempt to only serialize used properties?

Copy link
Contributor

Choose a reason for hiding this comment

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

i.e. tree-shake?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

right, previous behavior was that anything recognized as a function instanceof Function would be fully serialized, meaning static properties made a mess.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And namespaces more so :-)

@thantos thantos merged commit fe2e912 into main Jun 22, 2022
@thantos thantos deleted the optimize_function branch June 22, 2022 04:46
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

2 participants