Skip to content

feat: replace Map by plain old objects to support more browsers #78

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

Merged
merged 5 commits into from
Sep 15, 2019

Conversation

Mexx77
Copy link
Contributor

@Mexx77 Mexx77 commented Sep 4, 2019

Since we use basic Map features (get, set, has, delete) only, we can
as well just replace our maps by objects to support IE < 11 and other
browser that do not recognize ES6 specifications.
This keeps the bundle small and avoids the need of costly polyfills. We, the performance measurement teams, have a special interest in keeping our performance impact as low as possible.

nilskuhn and others added 3 commits August 20, 2019 15:14
Since we use basic Map features (get, set, has, delete) only, we can
as well just replace our maps by objects to support IE < 11 and other
browser that do not recognize ES6 specifications.
This keeps the bundle small and avoids the need of costy polyfills.
@Zizzamia Zizzamia self-requested a review September 8, 2019 23:39
src/perfume.ts Outdated
@@ -198,7 +206,7 @@ export default class Perfume {
// Get duration and change it to a two decimal value
const duration = this.perf.measure(metricName, metric);
const duration2Decimal = parseFloat(duration.toFixed(2));
this.metrics.delete(metricName);
delete this.metrics.metricName;
Copy link
Owner

Choose a reason for hiding this comment

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

This one should probably be delete this.metrics[metricName]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Owner

@Zizzamia Zizzamia Sep 11, 2019

Choose a reason for hiding this comment

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

This example should help explain my point
Screen Shot 2019-09-10 at 9 42 24 PM

which is, that delete this.metrics.metricName will delete the Key value metricName, and not the string contained inside the metricName variable.

Also, I should probably add a test to prevent this issue.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oh, I see your point. Will fix that...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

have fixed it. added a test to check proper deletion of metrics. this test fails with the previous implementation and passes with the fix as expected. :)

src/perfume.ts Outdated
@@ -164,14 +172,14 @@ export default class Perfume {
if (!this.checkMetricName(metricName)) {
return;
}
if (this.metrics.has(metricName)) {
if (this.metrics.hasOwnProperty(metricName)) {
Copy link
Owner

Choose a reason for hiding this comment

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

Based on https://jsperf.com/map-has-vs-object-hasownproperty results,
the most performant way would be simply to

if (this.metrics[metricName]) {

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good catch. Going to update this to use the fastest :) thx

Copy link
Owner

@Zizzamia Zizzamia left a comment

Choose a reason for hiding this comment

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

Amazing, thank you for supporting Perfume.js
🌕🦕🌲

@Zizzamia Zizzamia merged commit c86e540 into Zizzamia:master Sep 15, 2019
@Zizzamia Zizzamia added this to the v3.0.0 milestone Sep 15, 2019
@Zizzamia
Copy link
Owner

The code has been published under v3.0.0-beta.0

Please let me know if works all good!

Also, v3 is going to have some nice extra feature, but before the full roll-out, I'm going to have a couple of extra betas.

@Mexx77
Copy link
Contributor Author

Mexx77 commented Sep 16, 2019

thanks, have installed the new beta and will test it in the wild ;)

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.

3 participants