Skip to content

Cache the wd request dispatcher#14493

Merged
christian-bromann merged 6 commits intowebdriverio:mainfrom
dragosMC91:use-cached-wd-request-dispatcher
May 20, 2025
Merged

Cache the wd request dispatcher#14493
christian-bromann merged 6 commits intowebdriverio:mainfrom
dragosMC91:use-cached-wd-request-dispatcher

Conversation

@dragosMC91
Copy link
Contributor

Proposed changes

I noticed that a new agent is created for each individual wd request. Maybe i am missing something but this seems excessive.

I propose using a cached instance of the dispatcher.

I validated the performance improvement for this change via the performance tests referenced in the issue for this fix - #14492

Types of changes

  • Polish (an improvement for an existing feature)
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation update (improvements to the project's docs)
  • Specification changes (updates to WebDriver command specifications)
  • Internal updates (everything related to internal scripts, governance documentation and CI files)

Checklist

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have added the necessary documentation (if appropriate)
  • I have added proper type definitions for new commands (if appropriate)

Backport Request

//: # (The current main branch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against the v8 branch.)

  • This change is solely for v9 and doesn't need to be back-ported
  • Back-ported PR at #XXXXX

Reviewers: @webdriverio/project-committers

@pkg-pr-new
Copy link

pkg-pr-new bot commented May 18, 2025

Open in StackBlitz

eslint-plugin-wdio

npm i https://pkg.pr.new/webdriverio/webdriverio/eslint-plugin-wdio@14493

@wdio/allure-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/allure-reporter@14493

@wdio/appium-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/appium-service@14493

@wdio/browser-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browser-runner@14493

@wdio/browserstack-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/browserstack-service@14493

@wdio/cli

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cli@14493

@wdio/concise-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/concise-reporter@14493

@wdio/cucumber-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/cucumber-framework@14493

@wdio/config

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/config@14493

@wdio/dot-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/dot-reporter@14493

@wdio/firefox-profile-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/firefox-profile-service@14493

@wdio/globals

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/globals@14493

@wdio/jasmine-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/jasmine-framework@14493

@wdio/json-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/json-reporter@14493

@wdio/junit-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/junit-reporter@14493

@wdio/lighthouse-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/lighthouse-service@14493

@wdio/local-runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/local-runner@14493

@wdio/logger

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/logger@14493

@wdio/mocha-framework

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/mocha-framework@14493

@wdio/protocols

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/protocols@14493

@wdio/repl

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/repl@14493

@wdio/reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/reporter@14493

@wdio/runner

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/runner@14493

@wdio/sauce-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sauce-service@14493

@wdio/shared-store-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/shared-store-service@14493

@wdio/smoke-test-cjs-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-cjs-service@14493

@wdio/smoke-test-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-reporter@14493

@wdio/smoke-test-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/smoke-test-service@14493

@wdio/spec-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/spec-reporter@14493

@wdio/static-server-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/static-server-service@14493

@wdio/sumologic-reporter

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/sumologic-reporter@14493

@wdio/testingbot-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/testingbot-service@14493

@wdio/types

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/types@14493

@wdio/utils

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/utils@14493

webdriver

npm i https://pkg.pr.new/webdriverio/webdriverio/webdriver@14493

@wdio/webdriver-mock-service

npm i https://pkg.pr.new/webdriverio/webdriverio/@wdio/webdriver-mock-service@14493

webdriverio

npm i https://pkg.pr.new/webdriverio/webdriverio@14493

commit: 8a42dcf

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

I totally agree that we can be more efficient here. However the current implementation would not allow to have multiple WebDriver sessions with different options as we would cache one dispatcher per process. I wonder if we can store them in a map based on a given session id. Wdyt?

@dragosMC91
Copy link
Contributor Author

I totally agree that we can be more efficient here. However the current implementation would not allow to have multiple WebDriver sessions with different options as we would cache one dispatcher per process. I wonder if we can store them in a map based on a given session id. Wdyt?

i initially wanted to use a map, but thought each process would only have 1 set of options, defined at test start. So i missed this scenario you mentioned.
I will investigate how to implement your suggestion, will probably do so after work tomorrow

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

We should clean up session entries at some point otherwise the map may grow infinitely. One way could be to check if the request is a delete session request and clean up after.

@dragosMC91
Copy link
Contributor Author

We should clean up session entries at some point otherwise the map may grow infinitely. One way could be to check if the request is a delete session request and clean up after.

good idea, should i also add unit tests for this change ?

@christian-bromann
Copy link
Member

should i also add unit tests for this change ?

That would be great, thanks!

@dragosMC91
Copy link
Contributor Author

should i also add unit tests for this change ?

That would be great, thanks!

will do so tomorrow after work

@dragosMC91
Copy link
Contributor Author

@christian-bromann when there are no other change requests, i'd like to rerun the performance tests on the final version with the tests here https://github.com/dragosMC91/wdio-exclude-pattern-bug-highlight/blob/master/test/specs/suite1/validatePerformance.desktop.test.js
i'd appreciate it if we only merged after

Copy link
Member

@christian-bromann christian-bromann left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@christian-bromann christian-bromann added the PR: Polish 💅 PRs that contain improvements on existing features label May 19, 2025
@christian-bromann christian-bromann merged commit b70285e into webdriverio:main May 20, 2025
46 checks passed
@wdio-bot
Copy link
Contributor

Hey dragosMC91 👋

Thank you for your contribution to WebdriverIO! Your pull request has been marked as an "Expensable" contribution.

We've sent you an email with further instructions on how to claim your expenses from our development fund.
Please make sure to check your spam folder as well. If you have any questions, feel free to reach out to us at expense@webdriver.io or in the contributing channel on Discord.

We are looking forward to more contributions from you in the future 🙌

Have a nice day,
The WebdriverIO Team 🤖

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Expensable $50 💸 PR: Polish 💅 PRs that contain improvements on existing features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 Bug]: Webdriver creates a new agent object for each individual request which is expensive

3 participants