perf(console): rendering

This commit is contained in:
redhoodsu
2019-11-03 21:05:43 +08:00
parent b906228807
commit 28c43ed109
4 changed files with 115 additions and 12 deletions

View File

@@ -2217,6 +2217,20 @@ query.stringify({foo: 'bar', eruda: 'true'}); // -> 'foo=bar&eruda=true'
query.parse('name=eruda&name=eustia'); // -> {name: ['eruda', 'eustia']} query.parse('name=eruda&name=eustia'); // -> {name: ['eruda', 'eustia']}
``` ```
## raf
Shortcut for requestAnimationFrame.
Use setTimeout if native requestAnimationFrame is not supported.
```javascript
const id = raf(function tick() {
// Animation stuff
raf(tick);
});
raf.cancel(id);
```
## repeat ## repeat
Repeat string n-times. Repeat string n-times.

View File

@@ -19,7 +19,8 @@ import {
toArr, toArr,
keys, keys,
last, last,
throttle throttle,
raf
} from '../lib/util' } from '../lib/util'
let id = 0 let id = 0
@@ -452,7 +453,7 @@ export default class Logger extends Emitter {
this.renderViewport() this.renderViewport()
} }
_handleAsyncList() { _handleAsyncList(timeout = 20) {
const asyncList = this._asyncList const asyncList = this._asyncList
if (this._asyncTimer) return if (this._asyncTimer) return
@@ -460,16 +461,38 @@ export default class Logger extends Emitter {
this._asyncTimer = setTimeout(() => { this._asyncTimer = setTimeout(() => {
this._asyncTimer = null this._asyncTimer = null
let done = false let done = false
for (let i = 0; i < 20; i++) { const len = asyncList.length
const item = asyncList.shift() // insert faster if logs is huge, thus takes more time to render.
if (!item) { let timeout, num
done = true if (len < 1000) {
break num = 200
} timeout = 400
this.insertSync(item[0], item[1]) } else if (len < 5000) {
num = 500
timeout = 800
} else if (len < 10000) {
num = 800
timeout = 1000
} else if (len < 25000) {
num = 1000
timeout = 1200
} else if (len < 50000) {
num = 1500
timeout = 1500
} else {
num = 2000
timeout = 2500
} }
if (!done) this._handleAsyncList() if (num > len) {
}, 15) num = len
done = true
}
for (let i = 0; i < num; i++) {
const [type, args] = asyncList.shift()
this.insertSync(type, args)
}
if (!done) raf(() => this._handleAsyncList(timeout))
}, timeout)
} }
_injectGlobal() { _injectGlobal() {
each(this._global, (val, name) => { each(this._global, (val, name) => {

View File

@@ -6985,6 +6985,73 @@ export var pxToNum = _.pxToNum = (function (exports) {
return exports; return exports;
})({}); })({});
/* ------------------------------ raf ------------------------------ */
export var raf = _.raf = (function (exports) {
/* Shortcut for requestAnimationFrame.
*
* Use setTimeout if native requestAnimationFrame is not supported.
*/
/* example
* const id = raf(function tick() {
* // Animation stuff
* raf(tick);
* });
* raf.cancel(id);
*/
/* typescript
* export declare namespace raf {
* function cancel(id: number);
* }
* export declare function raf(cb: Function): number;
*/
/* dependencies
* now isBrowser
*/
var raf, cancel;
var lastTime = 0;
if (isBrowser) {
raf = window.requestAnimationFrame;
cancel = window.cancelAnimationFrame;
var vendors = ['ms', 'moz', 'webkit', 'o'];
for (var i = 0, len = vendors.length; i < len && !raf; i++) {
raf = window[vendors[i] + 'RequestAnimationFrame'];
cancel =
window[vendors[i] + 'CancelAnimationFrame'] ||
window[vendors[i] + 'CancelRequestAnimationFrame'];
}
}
raf =
raf ||
function(cb) {
var curTime = now();
var timeToCall = Math.max(0, 16 - (curTime - lastTime));
var id = setTimeout(function() {
cb(curTime + timeToCall);
}, timeToCall);
lastTime = curTime + timeToCall;
return id;
};
cancel =
cancel ||
function(id) {
clearTimeout(id);
};
raf.cancel = cancel;
exports = raf;
return exports;
})({});
/* ------------------------------ rmCookie ------------------------------ */ /* ------------------------------ rmCookie ------------------------------ */
export var rmCookie = _.rmCookie = (function (exports) { export var rmCookie = _.rmCookie = (function (exports) {

View File

@@ -10,7 +10,6 @@
height: 100%; height: 100%;
z-index: 100000; z-index: 100000;
color: $gray-dark; color: $gray-dark;
transform: translateZ(0);
font-family: $font-family; font-family: $font-family;
font-size: $font-size; font-size: $font-size;
direction: ltr; direction: ltr;