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

Support running Benchmark in Browser #14

Merged
merged 3 commits into from
Dec 4, 2023

Conversation

haven2world
Copy link
Contributor

I re-arrange code and split them into files so we can only import Benchmark in browser environment.
Replaced browser-process-hrtime with browser-hrtime which is newer and resolve a webpack issue
Replaced events with eventEmitter3 which is faster and also support browser

Though there is a bunch of code change, but I don't change any logic actually.

@haven2world
Copy link
Contributor Author

@mtkennerly could you help take a look?

@mtkennerly
Copy link
Owner

Hi! Thanks for your PR. I'm open to this, but I'd like to better understand the issues you encountered. The Karma example does run in the browser, although it's using Browserify - would your changes here mean that Browserify is no longer needed?

I re-arrange code and split them into files so we can only import Benchmark in browser environment.

I would have expected the other items to be tree-shaken. Why is it necessary to move the items out of index.ts?

Replaced browser-process-hrtime with browser-hrtime which is newer and resolve a webpack issue

Which Webpack issue does it solve? Is it related to kumavis/browser-process-hrtime#11 ?

@haven2world
Copy link
Contributor Author

Thanks for your review! Haha I'd like to appreciate your work first, this is the only library which meets my need. It saves my life.

I would have expected the other items to be tree-shaken. Why is it necessary to move the items out of index.ts?

On production, it's supposed to work, I didn't try it. My problem is, for webpack, tree-shaking happens on the minification phase and is not available on dev mode. So, on dev mode, webpack imports all code including reporters and some nodejs-only dependencies. After moving the code, we can import it like import { Benchmark } from 'kelonio/out/Benchmark'; to manually filter out the reporters which works well on dev mode.

Which Webpack issue does it solve? Is it related to kumavis/browser-process-hrtime#11 ?

Yes. I just accepted the suggestion given in this thread to replace browser-process-hrtime with browser-hrtime

@mtkennerly
Copy link
Owner

mtkennerly commented Dec 1, 2023

Thanks for the kind words :D I'm glad you've found it helpful.

I'm fine with the dependency changes here.

For the other issue, rather than move Benchmark, I think I'd rather move the code that relies on fs. That should just mean:

  • split reporters.ts into reporters/{jest,mocha,karma}.ts and then move BenchmarkFileState into the Jest file
  • don't export the reporters from index.ts (which is fine because they're really only used via the plugin modules)

That should result in a smaller diff and let you keep the nicer import { Benchmark } from "kelonio" style in your project.

Let me know if you'd like to make those changes in this PR :)

@haven2world
Copy link
Contributor Author

That's great! I'll refine my PR. Maybe I also need to change the Doc.

@haven2world
Copy link
Contributor Author

Updated the code.
I ran npm run docs and no new changes. I guess it's fine.

Copy link
Owner

@mtkennerly mtkennerly left a comment

Choose a reason for hiding this comment

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

Thanks! This is great.

It looks like the dependency changes got reset, but I can add those back after merging :)

I'll publish a new release shortly.

@mtkennerly mtkennerly merged commit 09f7577 into mtkennerly:master Dec 4, 2023
4 checks passed
mtkennerly added a commit that referenced this pull request Dec 4, 2023
mtkennerly added a commit that referenced this pull request Dec 4, 2023
@mtkennerly mtkennerly added this to the v0.10.0 milestone Dec 4, 2023
mtkennerly added a commit that referenced this pull request Dec 4, 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.

2 participants