Skip to content

some tweaks #2184

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 3 commits into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/globalConfig.js → src/GlobalConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,16 @@
* global config
* idle/worker etc
*/
const globalConfig = {
//dev env
dev: false,
//test env
test: false,
const GlobalConfig = {
//idle logging
idleLog: false,
//idle 时间阈值
idleTimeRemaining: 8,
//idle 超时阈值
idleTimeout: 1000,
//worker 数量
workerCount: 0,
//worker 通信并发数量
workerConcurrencyCount: 5
workerCount: window.MAPTALKS_WORKER_COUNT || 0,
//每个Worker Message中封装的task message数量
taskCountPerWorkerMessage: 5
};
export default globalConfig;
export default GlobalConfig;
6 changes: 3 additions & 3 deletions src/core/MicroTask.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { requestAnimFrame } from './util';
import { isFunction, isNil, isNumber } from './util/common';
import { getGlobalWorkerPool } from './worker/WorkerPool';
import Browser from './Browser';
import globalConfig from '../globalConfig';
import GlobalConfig from '../GlobalConfig';

let tasks = [];

Expand Down Expand Up @@ -88,7 +88,7 @@ function loop() {
}

function frameLoop(deadline) {
const { idleTimeRemaining, idleLog, idleTimeout } = globalConfig;
const { idleTimeRemaining, idleLog, idleTimeout } = GlobalConfig;
if (Browser.requestIdleCallback) {
if (deadline && deadline.timeRemaining) {
const t = deadline.timeRemaining();
Expand Down Expand Up @@ -118,7 +118,7 @@ export function startTasks() {
return;
}
started = true;
const { idleTimeout } = globalConfig;
const { idleTimeout } = GlobalConfig;
if (Browser.requestIdleCallback) {
requestIdleCallback(frameLoop, { timeout: idleTimeout });
} else {
Expand Down
98 changes: 0 additions & 98 deletions src/core/util/pick.js

This file was deleted.

15 changes: 5 additions & 10 deletions src/core/worker/WorkerPool.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
// import { requestAnimFrame } from '../util';
import { setWorkerPool, setWorkersCreated } from './CoreWorkers';
import { getWorkerSourcePath } from './Worker';
import globalConfig from '../../globalConfig';
import GlobalConfig from '../../GlobalConfig';

const hardwareConcurrency = typeof window !== 'undefined' ? (window.navigator.hardwareConcurrency || 4) : 0;
const workerCount = Math.max(Math.floor(hardwareConcurrency / 2), 1);
const hardwareWorkerCount = Math.max(Math.floor(hardwareConcurrency / 2), 1);

class MessageBatch {
constructor(limit = 50) {
Expand Down Expand Up @@ -43,7 +43,7 @@ class MessageBatch {
export default class WorkerPool {
constructor() {
this.active = {};
this.workerCount = typeof window !== 'undefined' ? (globalConfig.workerCount || window.MAPTALKS_WORKER_COUNT || workerCount) : 0;
this.workerCount = typeof window !== 'undefined' ? (GlobalConfig.workerCount || hardwareWorkerCount) : 0;
this._messages = [];
this._messageBuffers = [];
}
Expand Down Expand Up @@ -107,19 +107,14 @@ export default class WorkerPool {
return this.workers || [];
}

broadcastMessage(message) {
broadcastIdleMessage() {
const workers = this.getWorkers();
workers.forEach(worker => {
worker.postMessage({ messageType: message, messageCount: globalConfig.workerConcurrencyCount });
worker.postMessage({ messageType: 'idle', messageCount: GlobalConfig.taskCountPerWorkerMessage });
});
return this;
}

broadcastIdleMessage() {
this.broadcastMessage('idle');
return this;
}

}

let globalWorkerPool;
Expand Down
2 changes: 1 addition & 1 deletion src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { version } from '../package.json';
export { default as globalconfig } from './globalConfig';
export { default as Globalconfig } from './GlobalConfig';
export * from './core/Constants';
export { default as Browser } from './core/Browser';
import * as Util from './core/util';
Expand Down
10 changes: 2 additions & 8 deletions src/map/Map.Topo.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { INTERNAL_LAYER_PREFIX } from '../core/Constants';
import { isNil, isString, isArrayHasData, pushIn, isFunction } from '../core/util';
import { isGLRenderLayer, layerIsBlankInPoint } from '../core/util/pick';
import Coordinate from '../geo/Coordinate';
import Point from '../geo/Point';
import Map from './Map';
Expand Down Expand Up @@ -108,17 +107,12 @@ Map.include(/** @lends Map.prototype */ {
opts.tolerance = opts.tolerance || 0;
opts.tolerance += layer.options.geometryEventTolerance;
}
//only gllayer,exclude canvas layer
const isGLLayer = isGLRenderLayer(layer);
const isBlank = isGLLayer && layerIsBlankInPoint(layer, containerPoint, opts.tolerance);
if (!isBlank && layer._hasGeoListeners && isMapGeometryEvent && opts.eventTypes.indexOf('mousemove') >= 0) {
if (layer._hasGeoListeners && isMapGeometryEvent && opts.eventTypes.indexOf('mousemove') >= 0) {
if (!layer._hasGeoListeners(opts.eventTypes)) {
return [];
}
}
if (isBlank) {
result = [];
} else if (layer.identifyAtPoint) {
if (layer.identifyAtPoint) {
result = layer.identifyAtPoint(containerPoint, opts);
} else if (coordinate && layer.identify) {
result = layer.identify(coordinate, opts);
Expand Down
6 changes: 0 additions & 6 deletions src/renderer/layer/vectorlayer/VectorLayerCanvasRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -552,12 +552,6 @@ class VectorLayerRenderer extends OverlayLayerCanvasRenderer {
return this.constructor === VectorLayerRenderer;
}

_alwaysDraw() {
if (this.canvas && this.isProgressiveRender()) {
this.canvas._drawn = true;
}
}

isProgressiveRender() {
const layer = this.layer;
if (!layer) {
Expand Down