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

perf: Adjust queue track size automatically for shared layers. #1202

Merged
merged 1 commit into from
May 11, 2022
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
### Improvements

- Support polygon annotations with holes through geojson ([#1201](../../pull/1201))
- Adjust queue track size based on number of tile layers ([#1202](../../pull/1202))

## Version 1.8.3

Expand Down
27 changes: 26 additions & 1 deletion src/fetchQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ var fetchQueue = function (options) {
this._size = options.size || 6;
this._initialSize = options.initialSize || 0;
this._track = options.track || 600;
this._initialTrack = this._track;
this._needed = options.needed || null;
this._batch = false;

Expand Down Expand Up @@ -76,6 +77,30 @@ var fetchQueue = function (options) {
}
});

/**
* Get/set the track size. This is used to determine when to check if
* entries can be discarded.
* @property {number} track The number of entries to track without checking
* for discards.
* @name geo.fetchQueue#track
*/
Object.defineProperty(this, 'track', {
get: function () { return m_this._track; },
set: function (n) { m_this._track = n; }
});

/**
* Get/set the initial track size. Unless changed, this is the value used
* for track on class initialization.
* @property {number} initialTrack The number of entries to track without
* checking for discards.
* @name geo.fetchQueue#intitialTrack
*/
Object.defineProperty(this, 'initialTrack', {
get: function () { return m_this._initialTrack; },
set: function (n) { m_this._initialTrack = n; }
});

/**
* Get the current queue size. Read only.
* @property {number} length The current queue size.
Expand Down Expand Up @@ -157,7 +182,7 @@ var fetchQueue = function (options) {
defer.__fetchQueue._batch = m_this._batch;
if (atEnd) {
m_this._queue.push(defer);
} else if (!this._batch) {
} else if (!m_this._batch) {
m_this._queue.unshift(defer);
} else {
for (var i = 0; i < m_this._queue.length; i += 1) {
Expand Down
20 changes: 18 additions & 2 deletions src/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var featureLayer = require('./featureLayer');
* @property {function} [tilesAtZoom=null] A function that is given a zoom
* level and returns `{x: (num), y: (num)}` with the number of tiles at that
* zoom level.
* @property {number} [cacheSize=400] The maximum number of tiles to cache.
* @property {number} [cacheSize=600] The maximum number of tiles to cache.
* The default is 200 if keepLower is false.
* @property {geo.fetchQueue} [queue] A fetch queue to use. If unspecified, a
* new queue is created.
Expand Down Expand Up @@ -193,6 +193,10 @@ var tileLayer = function (arg) {
arg = $.extend(true, {}, this.constructor.defaults, arg || {});
if (!arg.cacheSize) {
// this size should be sufficient for a 4k display
// where display size is (w, h), minimum tile dimension is ts, and total
// number of levels is ml, this is roughly
// sum([(math.ceil((w**2+h**2)**0.5 / (ts*2**l)) + 1) *
// (math.ceil(min(w, h) / (ts*2**l)) + 1) for l in range(ml)])
arg.cacheSize = arg.keepLower ? 600 : 200;
}
if ($.type(arg.subdomains) === 'string') {
Expand Down Expand Up @@ -261,6 +265,9 @@ var tileLayer = function (arg) {
});
this._queue._tileLayers = this._queue._tileLayers || [];
this._queue._tileLayers.push(m_this);
if (this._queue.initialTrack && this._queue.track) {
this._queue.track = this._queue.initialTrack * this._queue._tileLayers.length;
}

var m_tileOffsetValues = {};

Expand Down Expand Up @@ -310,10 +317,16 @@ var tileLayer = function (arg) {
if (m_this._queue !== queue) {
if (this._queue && this._queue._tileLayers && this._queue._tileLayers.indexOf(m_this) >= 0) {
this._queue._tileLayers.splice(this._queue._tileLayers.indexOf(m_this), 1);
if (this._queue.initialTrack && this._queue.track && this._queue._tileLayers.length) {
this._queue.track = this._queue.initialTrack * this._queue._tileLayers.length;
}
}
m_this._queue = queue;
m_this._queue._tileLayers = m_this._queue._tileLayers || [];
m_this._queue._tileLayers.push(m_this);
if (m_this._queue.initialTrack && m_this._queue.track) {
m_this._queue.track = m_this._queue.initialTrack * m_this._queue._tileLayers.length;
}
}
}
});
Expand Down Expand Up @@ -1736,6 +1749,9 @@ var tileLayer = function (arg) {
m_exited = true;
if (this._queue && this._queue._tileLayers && this._queue._tileLayers.indexOf(m_this) >= 0) {
this._queue._tileLayers.splice(this._queue._tileLayers.indexOf(m_this), 1);
if (this._queue.initialTrack && this._queue.track && this._queue._tileLayers.length) {
this._queue.track = this._queue.initialTrack * this._queue._tileLayers.length;
}
}
return m_this;
};
Expand Down Expand Up @@ -1765,7 +1781,7 @@ tileLayer.defaults = {
topDown: false,
keepLower: true,
idleAfter: 'view',
// cacheSize: 400, // set depending on keepLower
// cacheSize: 600, // set depending on keepLower
tileRounding: Math.round,
attribution: '',
animationDuration: 0
Expand Down
12 changes: 12 additions & 0 deletions tests/cases/fetchQueue.js
Original file line number Diff line number Diff line change
Expand Up @@ -273,5 +273,17 @@ describe('geo.core.fetchQueue', function () {

process();
});

it('track and initialTrack size', function () {
var q = geo.fetchQueue({track: 10});
expect(q.track).toBe(10);
expect(q.initialTrack).toBe(10);
q.track = 20;
expect(q.track).toBe(20);
expect(q.initialTrack).toBe(10);
q.initialTrack = 30;
expect(q.track).toBe(20);
expect(q.initialTrack).toBe(30);
});
});
});
2 changes: 2 additions & 0 deletions tests/cases/tileLayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -464,8 +464,10 @@ describe('geo.tileLayer', function () {
var origQueue = layer2.queue;
layer2.queue = layer.queue;
expect(layer.queue._tileLayers.length).toBe(2);
expect(layer.queue.track).toBe(layer.queue.initialTrack * 2);
layer2.queue = origQueue;
expect(layer.queue._tileLayers.length).toBe(1);
expect(layer.queue.track).toBe(layer.queue.initialTrack);
});
it('reference', function () {
var m = map(), layer;
Expand Down