add perf marks
This commit is contained in:
parent
2c31746ae7
commit
95290afca7
5
package-lock.json
generated
5
package-lock.json
generated
|
@ -3970,6 +3970,11 @@
|
||||||
"object-visit": "1.0.1"
|
"object-visit": "1.0.1"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"marky": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/marky/-/marky-1.2.0.tgz",
|
||||||
|
"integrity": "sha1-lhftZHu76o9F0ZUm2jPexwYG30I="
|
||||||
|
},
|
||||||
"math-expression-evaluator": {
|
"math-expression-evaluator": {
|
||||||
"version": "1.2.17",
|
"version": "1.2.17",
|
||||||
"resolved": "https://registry.npmjs.org/math-expression-evaluator/-/math-expression-evaluator-1.2.17.tgz",
|
"resolved": "https://registry.npmjs.org/math-expression-evaluator/-/math-expression-evaluator-1.2.17.tgz",
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
"intersection-observer": "^0.5.0",
|
"intersection-observer": "^0.5.0",
|
||||||
"intl-relativeformat": "^2.1.0",
|
"intl-relativeformat": "^2.1.0",
|
||||||
"lodash": "^4.17.4",
|
"lodash": "^4.17.4",
|
||||||
|
"marky": "^1.2.0",
|
||||||
"node-fetch": "^1.7.3",
|
"node-fetch": "^1.7.3",
|
||||||
"node-sass": "^4.7.2",
|
"node-sass": "^4.7.2",
|
||||||
"npm-run-all": "^4.1.2",
|
"npm-run-all": "^4.1.2",
|
||||||
|
|
|
@ -12,12 +12,14 @@
|
||||||
|
|
||||||
import debounce from 'lodash/debounce'
|
import debounce from 'lodash/debounce'
|
||||||
import throttle from 'lodash/throttle'
|
import throttle from 'lodash/throttle'
|
||||||
|
import { mark, stop } from '../_utils/marks'
|
||||||
|
|
||||||
const SCROLL_EVENT_DELAY = 300
|
const SCROLL_EVENT_DELAY = 300
|
||||||
const RESIZE_EVENT_DELAY = 700
|
const RESIZE_EVENT_DELAY = 700
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate() {
|
oncreate() {
|
||||||
|
mark('onCreate Layout')
|
||||||
this.observe('innerHeight', debounce(() => {
|
this.observe('innerHeight', debounce(() => {
|
||||||
// respond to window resize events
|
// respond to window resize events
|
||||||
this.store.set({
|
this.store.set({
|
||||||
|
@ -29,6 +31,7 @@
|
||||||
scrollHeight: this.refs.node.scrollHeight,
|
scrollHeight: this.refs.node.scrollHeight,
|
||||||
offsetHeight: this.refs.node.offsetHeight
|
offsetHeight: this.refs.node.offsetHeight
|
||||||
})
|
})
|
||||||
|
stop('onCreate Layout')
|
||||||
},
|
},
|
||||||
components: {
|
components: {
|
||||||
Nav
|
Nav
|
||||||
|
@ -36,7 +39,11 @@
|
||||||
store: () => virtualListStore,
|
store: () => virtualListStore,
|
||||||
events: {
|
events: {
|
||||||
scroll(node, callback) {
|
scroll(node, callback) {
|
||||||
const onScroll = throttle(callback, SCROLL_EVENT_DELAY, {
|
const onScroll = throttle(event => {
|
||||||
|
mark('onScroll')
|
||||||
|
callback(event)
|
||||||
|
stop('onScroll')
|
||||||
|
}, SCROLL_EVENT_DELAY, {
|
||||||
leading: true,
|
leading: true,
|
||||||
trailing: true
|
trailing: true
|
||||||
})
|
})
|
||||||
|
|
|
@ -182,6 +182,7 @@
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
import Avatar from './Avatar.html'
|
import Avatar from './Avatar.html'
|
||||||
|
import { mark, stop } from '../_utils/marks'
|
||||||
import IntlRelativeFormat from 'intl-relativeformat'
|
import IntlRelativeFormat from 'intl-relativeformat'
|
||||||
const relativeFormat = new IntlRelativeFormat('en-US');
|
const relativeFormat = new IntlRelativeFormat('en-US');
|
||||||
|
|
||||||
|
@ -192,15 +193,12 @@
|
||||||
computed: {
|
computed: {
|
||||||
createdAtDate: (status) => status.created_at,
|
createdAtDate: (status) => status.created_at,
|
||||||
relativeDate: (createdAtDate) => {
|
relativeDate: (createdAtDate) => {
|
||||||
return relativeFormat.format(new Date(createdAtDate))
|
mark('compute relativeDate')
|
||||||
|
let res = relativeFormat.format(new Date(createdAtDate))
|
||||||
|
stop('compute relativeDate')
|
||||||
|
return res
|
||||||
},
|
},
|
||||||
original: (status) => status.reblog ? status.reblog.account : status.account
|
original: (status) => status.reblog ? status.reblog.account : status.account
|
||||||
},
|
|
||||||
methods: {
|
|
||||||
alert: function (e) {
|
|
||||||
e.preventDefault()
|
|
||||||
window.alert(e.target)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -15,6 +15,7 @@
|
||||||
import StatusListItem from './StatusListItem.html'
|
import StatusListItem from './StatusListItem.html'
|
||||||
import VirtualList from './VirtualList.html'
|
import VirtualList from './VirtualList.html'
|
||||||
import { splice, push } from 'svelte-extras'
|
import { splice, push } from 'svelte-extras'
|
||||||
|
import { mark, stop } from '../_utils/marks'
|
||||||
|
|
||||||
let i = -1
|
let i = -1
|
||||||
|
|
||||||
|
@ -37,31 +38,13 @@
|
||||||
splice: splice,
|
splice: splice,
|
||||||
push: push,
|
push: push,
|
||||||
addMoreItems() {
|
addMoreItems() {
|
||||||
console.log('addMoreItems')
|
mark('addMoreItems')
|
||||||
let statuses = this.get('statuses')
|
let statuses = this.get('statuses')
|
||||||
if (statuses) {
|
if (statuses) {
|
||||||
let itemsToAdd = createData()
|
let itemsToAdd = createData()
|
||||||
if (itemsToAdd.length) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
let importantFirstItem = itemsToAdd
|
|
||||||
this.splice('statuses', statuses.length, 0, ...itemsToAdd)
|
this.splice('statuses', statuses.length, 0, ...itemsToAdd)
|
||||||
}
|
}
|
||||||
},
|
stop('addMoreItems')
|
||||||
addTheseItems(items) {
|
|
||||||
if (!items.length) {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
this.push(items.pop())
|
|
||||||
while (items.length) {
|
|
||||||
this.addItemLazily(items.pop())
|
|
||||||
}
|
|
||||||
},
|
|
||||||
addItemLazily(item) {
|
|
||||||
requestIdleCallback(() => {
|
|
||||||
this.push(item)
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,15 +16,18 @@
|
||||||
<script>
|
<script>
|
||||||
import VirtualListItem from './VirtualListItem'
|
import VirtualListItem from './VirtualListItem'
|
||||||
import { virtualListStore } from '../_utils/virtualListStore'
|
import { virtualListStore } from '../_utils/virtualListStore'
|
||||||
|
import { mark, stop } from '../_utils/marks'
|
||||||
|
|
||||||
const DISTANCE_FROM_BOTTOM_TO_FIRE = 400
|
const DISTANCE_FROM_BOTTOM_TO_FIRE = 400
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
oncreate () {
|
oncreate () {
|
||||||
this.observe('items', (items) => {
|
this.observe('items', (items) => {
|
||||||
|
mark('set items')
|
||||||
this.store.set({
|
this.store.set({
|
||||||
items: items
|
items: items
|
||||||
})
|
})
|
||||||
|
stop('set items')
|
||||||
})
|
})
|
||||||
|
|
||||||
let observedOnce = false
|
let observedOnce = false
|
||||||
|
|
|
@ -20,6 +20,7 @@
|
||||||
</style>
|
</style>
|
||||||
<script>
|
<script>
|
||||||
import { virtualListStore } from '../_utils/virtualListStore'
|
import { virtualListStore } from '../_utils/virtualListStore'
|
||||||
|
import { mark, stop } from '../_utils/marks'
|
||||||
|
|
||||||
let updateItemHeights = {}
|
let updateItemHeights = {}
|
||||||
let promise = Promise.resolve()
|
let promise = Promise.resolve()
|
||||||
|
@ -44,6 +45,7 @@
|
||||||
if (!updatedKeys.length) {
|
if (!updatedKeys.length) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
mark('batch update VirtualListItem')
|
||||||
// batch all updates to itemHeights for better perf
|
// batch all updates to itemHeights for better perf
|
||||||
let itemHeights = this.store.get('itemHeights')
|
let itemHeights = this.store.get('itemHeights')
|
||||||
for (key of updatedKeys) {
|
for (key of updatedKeys) {
|
||||||
|
@ -53,6 +55,7 @@
|
||||||
itemHeights: itemHeights
|
itemHeights: itemHeights
|
||||||
})
|
})
|
||||||
updateItemHeights = {}
|
updateItemHeights = {}
|
||||||
|
stop('batch update VirtualListItem')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
intersectionObserver.observe(this.refs.node)
|
intersectionObserver.observe(this.refs.node)
|
||||||
|
|
13
routes/_utils/marks.js
Normal file
13
routes/_utils/marks.js
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
import { mark as markyMark, stop as markyStop } from 'marky'
|
||||||
|
import noop from 'lodash/noop'
|
||||||
|
|
||||||
|
const enableMarks = typeof window !== 'undefined' &&
|
||||||
|
new URLSearchParams(location.search).get('marks') === 'true'
|
||||||
|
|
||||||
|
const mark = enableMarks ? markyMark : noop
|
||||||
|
const stop = enableMarks ? markyStop : noop
|
||||||
|
|
||||||
|
export {
|
||||||
|
mark,
|
||||||
|
stop
|
||||||
|
}
|
|
@ -1,4 +1,5 @@
|
||||||
import { Store } from 'svelte/store.js'
|
import { Store } from 'svelte/store.js'
|
||||||
|
import { mark, stop } from '../_utils/marks'
|
||||||
|
|
||||||
class VirtualListStore extends Store {
|
class VirtualListStore extends Store {
|
||||||
}
|
}
|
||||||
|
@ -11,6 +12,7 @@ const virtualListStore = new VirtualListStore({
|
||||||
virtualListStore.compute('visibleItems',
|
virtualListStore.compute('visibleItems',
|
||||||
['items', 'scrollTop', 'itemHeights', 'offsetHeight'],
|
['items', 'scrollTop', 'itemHeights', 'offsetHeight'],
|
||||||
(items, scrollTop, itemHeights, offsetHeight) => {
|
(items, scrollTop, itemHeights, offsetHeight) => {
|
||||||
|
mark('compute visibleItems')
|
||||||
let renderBuffer = 3 * offsetHeight
|
let renderBuffer = 3 * offsetHeight
|
||||||
let visibleItems = []
|
let visibleItems = []
|
||||||
let totalOffset = 0
|
let totalOffset = 0
|
||||||
|
@ -38,6 +40,7 @@ virtualListStore.compute('visibleItems',
|
||||||
index: i
|
index: i
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
stop('compute visibleItems')
|
||||||
return visibleItems
|
return visibleItems
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue