mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-28 10:31:20 -08:00
feat: enhance Danmuku plugin with batch processing for top calculations
- Implemented a callback pool in the Web Worker to handle concurrent requests without overwriting onmessage. - Modified postMessage to generate unique IDs for messages and store corresponding callbacks. - Improved state management by using in-place deletion for removing danmu from state pools. - Optimized the rendering loop to batch calculate the top positions of danmu elements, reducing DOM reads and improving performance. - Added a new function getDanmuTopBatch in the worker to handle batch requests for top calculations.
This commit is contained in:
1 parent
0bdc59e446
commit
1841f754dc
4 files changed
+251
-65
No files matched your search
@@ -135,12 +135,29 @@ function getDanmuTop({ target, visibles, clientWidth, clientHeight, marginBottom
|
||||
}
|
||||
}
|
||||
|
||||
function getDanmuTopBatch({ targets, visibles, clientWidth, clientHeight, marginBottom, marginTop, antiOverlap }) {
|
||||
if (!Array.isArray(targets) || targets.length === 0)
|
||||
return []
|
||||
|
||||
return targets.map((target) => {
|
||||
return getDanmuTop({
|
||||
target,
|
||||
visibles,
|
||||
clientWidth,
|
||||
clientHeight,
|
||||
marginBottom,
|
||||
marginTop,
|
||||
antiOverlap,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
onmessage = (event) => {
|
||||
const { data } = event
|
||||
if (!data.id || !data.type)
|
||||
return
|
||||
|
||||
const fns = { getDanmuTop }
|
||||
const fns = { getDanmuTop, getDanmuTopBatch }
|
||||
const fn = fns[data.type]
|
||||
const result = fn(data)
|
||||
|
||||
|
||||
Reference in new issue
Block a user