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
Use comlink in workers #5915
Use comlink in workers #5915
Conversation
export const filterSortData = memoizeOne( | ||
async ( | ||
data: DataTableRowData[], | ||
columns: DataTableColumnContainer, |
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 type was wrong, I replaced that with type SortableColumnContainer
which I extracted from HaDataTable["_sortColumns"]
return filterData(data, columns, filter.toUpperCase()); | ||
} | ||
); | ||
const filterSortData = ( |
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.
I've removed all the memoization because of the copying.
if (!worker) { | ||
worker = wrap(new Worker("./sort_filter_worker", { type: "module" })); | ||
} | ||
|
||
return await worker.filterSortData( | ||
data, | ||
columns, | ||
filter, | ||
direction, | ||
sortColumn | ||
); |
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.
To disable the built-in worker and use the API directly:
const workerAPI = await import("./sort_filter_worker");
return workerAPI.api.filterSortData(…)
Breaking change
Proposed change
This migrates our two worker scripts to use
new Worker(…)
and useworker-plugin
instead ofworkerize-loader
to automatically move this worker script into a chunk. Workerize did two things: move script + dependencies into a chunk and create an async API for it.With worker-plugin + comlink we get the same experience except it's in two parts.
To help see what is going on, I have also extracted the code that interacts with the worker into standalone functions.
However, there is a downside to
comlink
: it requires ES proxies.We have two options:
This PR implements the 1st option as it keeps our code more consistent. Easier to test.
Also, I saw that memoizeOne was used in the web worker for sorting/filtering. However, when data is copied from the UI thread to a worker thread, it's… copied :) So it can never hit the memoize fast-path of being equal to the last passed in data.
Type of change
Example configuration
Additional information
Checklist
If user exposed functionality or configuration variables are added/changed: