From 7aa2fdd70f193928289e63331864734b450d1a4b Mon Sep 17 00:00:00 2001 From: puckey Date: Thu, 8 Oct 2020 11:25:41 +0200 Subject: [PATCH 1/5] refactor - removed unnecessary and sometimes faulty return type definitions - improve window typing in update_benchmarks and replace groupBy with reduce - Remove T and I prefixes from types (see https://stackoverflow.com/questions/31876947/confused-about-the-interface-and-class-coding-guidelines-for-typescript/41967120#41967120 for reasons) - fix issue where a mac could be detected as an iphone (when amd processors arrive) - add isIOS to deviceInfo - turn off explicit-module-boundary-types eslint rule --- .eslintrc.js | 1 + example/index.ts | 2 +- scripts/update_benchmarks.ts | 206 +++++++++++++--------------- src/index.ts | 54 ++++---- src/internal/deobfuscateAppleGpu.ts | 2 +- src/internal/deobfuscateRenderer.ts | 2 +- src/internal/deviceInfo.ts | 7 +- src/internal/getGPUVersion.ts | 2 +- src/internal/getWebGLContext.ts | 2 +- src/types/index.ts | 19 ++- test/index.test.ts | 103 +++++++------- 11 files changed, 182 insertions(+), 218 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0d8ae6d..ad60d0e 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -13,6 +13,7 @@ module.exports = { sourceType: 'module', }, rules: { + '@typescript-eslint/explicit-module-boundary-types': OFF, '@typescript-eslint/ban-ts-ignore': OFF, 'sort-keys': [ ERROR, diff --git a/example/index.ts b/example/index.ts index 322f9ab..d46f965 100644 --- a/example/index.ts +++ b/example/index.ts @@ -1,7 +1,7 @@ // Application import { getGPUTier } from '../src'; -(async (): Promise => { +(async () => { const data = await getGPUTier({ benchmarksURL: '/build/benchmarks', }); diff --git a/scripts/update_benchmarks.ts b/scripts/update_benchmarks.ts index 3bdd8e1..887e149 100755 --- a/scripts/update_benchmarks.ts +++ b/scripts/update_benchmarks.ts @@ -21,14 +21,6 @@ const types = [ 'geforce', ]; -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const groupBy = (xs: any[], key: number | string): any => - // eslint-disable-next-line @typescript-eslint/no-explicit-any - xs.reduce((rv: any, x: any): any => { - (rv[x[key]] = rv[x[key]] || []).push(x); - return rv; - }, {}); - type BenchmarkRow = { date: string; device: string; @@ -38,43 +30,53 @@ type BenchmarkRow = { resolution: string; }; -(async (): Promise => { +(async () => { const browser = await puppeteer.launch({ headless: true }); const benchmarks = await getBenchmarks(); await Promise.all( - [true, false].map( - (mobile): Promise => exportBenchmarks(benchmarks, mobile) - ) + [true, false].map((mobile) => exportBenchmarks(benchmarks, mobile)) ); await browser.close(); - async function getBenchmarks(): Promise { + async function getBenchmarks() { const page = await browser.newPage(); await page.goto(BENCHMARK_URL, { waitUntil: 'networkidle2' }); - - return (await page.evaluate((): BenchmarkRow[] => - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (window as any).gpuName + type Optional = Pick, K> & Omit; + + return await page.evaluate((): BenchmarkRow[] => { + const { + firstResult, + deviceName, + fpses, + gpuNameLookup, + screenSizeLookup, + screenSizes, + gpuName, + formFactorLookup, + formFactor, + } = (window as unknown) as { + firstResult: string[]; + deviceName: string[]; + fpses: string[]; + gpuNameLookup: string[]; + screenSizeLookup: string[]; + screenSizes: number[]; + gpuName: number[]; + formFactorLookup: string[]; + formFactor: number[]; + }; + return gpuName .map( - (gpuIndex: number, index: number): Partial => ({ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - date: (window as any).firstResult[index], - // eslint-disable-next-line @typescript-eslint/no-explicit-any - device: (window as any).deviceName[index].toLowerCase(), + (gpuIndex, index): Optional => ({ + date: firstResult[index], + device: deviceName[index].toLowerCase(), fps: - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (window as any).fpses[index] === '' + fpses[index] === '' ? undefined - : Math.round( - Number( - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (window as any).fpses[index].replace(/[^0-9.]+/g, '') - ) - ), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - gpu: (window as any).gpuNameLookup[gpuIndex] + : Math.round(Number(fpses[index].replace(/[^0-9.]+/g, ''))), + gpu: gpuNameLookup[gpuIndex] .toLowerCase() .replace(/\s*\([^\)]+(\))/g, '') .replace(/([0-9]+)\/[^ ]+/, '$1') @@ -82,111 +84,87 @@ type BenchmarkRow = { /x\.org |inc\. |open source technology center |imagination technologies |™ |nvidia corporation |apple inc\. |advanced micro devices, inc\. | series$| edition$| graphics$/g, '' ), - - // eslint-disable-next-line @typescript-eslint/no-explicit-any - mobile: (window as any).formFactorLookup[ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (window as any).formFactor[index] - ].includes('mobile'), - // eslint-disable-next-line @typescript-eslint/no-explicit-any - resolution: (window as any).screenSizeLookup[ - // eslint-disable-next-line @typescript-eslint/no-explicit-any - (window as any).screenSizes[index] - ], + mobile: formFactorLookup[formFactor[index]].includes('mobile'), + resolution: screenSizeLookup[screenSizes[index]], }) ) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - .sort((a: any, b: any): number => { - return a.date.localeCompare(b.date); - }) - .filter(({ fps }: { fps: number }): boolean => fps !== undefined) - )) as BenchmarkRow[]; + .sort((a, b) => a.date.localeCompare(b.date)) + .filter((row): row is BenchmarkRow => row.fps !== undefined); + }); } - async function exportBenchmarks( - rows: BenchmarkRow[], - isMobile: boolean - ): Promise { - const getOutputFilename = (type: string): string => + async function exportBenchmarks(rows: BenchmarkRow[], isMobile: boolean) { + const getOutputFilename = (type: string) => `${isMobile ? 'm' : 'd'}-${type}.json`; rows = rows.filter( - ({ mobile, gpu }: BenchmarkRow): boolean => + ({ mobile, gpu }) => mobile === isMobile && types.filter((type): boolean => gpu.includes(type)).length > 0 ); const rowsByGpu = Object.values( - groupBy(rows, 'gpu') as { - [k: string]: BenchmarkRow[]; - } + rows.reduce((groupedByKey, row) => { + const groupKey = row.gpu; + (groupedByKey[groupKey] = groupedByKey[groupKey] || []).push(row); + return groupedByKey; + }, {} as Record) ); return Promise.all([ - ...types.map( - (type): Promise => { - const typeModels = rowsByGpu - .filter(([{ gpu }]: BenchmarkRow[]): boolean => gpu.includes(type)) - // eslint-disable-next-line @typescript-eslint/no-explicit-any - .map((rows: any): any => { - const { gpu } = rows[0]; - const isBlacklisted = blacklistedModels.find( - (blacklistedModel: string): boolean => - gpu.includes(blacklistedModel) - ); - - return [ - gpu, - getGPUVersion(gpu), - isBlacklisted ? 1 : 0, - Object.entries( - rows.reduce( - ( - fpsByResolution: { [k: string]: [string, number] }, - { - resolution, - fps, - device, - }: { resolution: string; fps: number; device: string } - ): { [k: string]: [string, number] } => { - fpsByResolution[resolution] = [ - device, - isBlacklisted ? -1 : fps, - ]; - return fpsByResolution; - }, - {} - ) + ...types.map((type) => { + const typeModels = rowsByGpu + .filter(([{ gpu }]) => gpu.includes(type)) + .map((rows) => { + const { gpu } = rows[0]; + const isBlacklisted = blacklistedModels.find((blacklistedModel) => + gpu.includes(blacklistedModel) + ); + + return [ + gpu, + getGPUVersion(gpu), + isBlacklisted ? 1 : 0, + Object.entries( + rows.reduce( + ( + fpsByResolution: { [k: string]: [string, number] }, + { resolution, fps, device } + ) => { + fpsByResolution[resolution] = [ + device, + isBlacklisted ? -1 : fps, + ]; + return fpsByResolution; + }, + {} ) - // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore: Type 'unknown' must have a '[Symbol.iterator]()' method that returns an iterator - .map(([resolution, [device, fps]]) => { - const [width, height] = resolution.split(' x ').map(Number); - - return isMobile - ? ([width, height, fps, device] as const) - : ([width, height, fps] as const); - }) - .sort(([, aW, aH], [, bW, bH]): number => aW * aH - bW * bH), - ]; - }); - - if (typeModels.length === 0) { - return Promise.resolve(); - } - - return outputFile(getOutputFilename(type), typeModels); + ) + .map(([resolution, [device, fps]]) => { + const [width, height] = resolution.split(' x ').map(Number); + + return isMobile + ? ([width, height, fps, device] as const) + : ([width, height, fps] as const); + }) + .sort(([, aW, aH], [, bW, bH]) => aW * aH - bW * bH), + ]; + }); + + if (typeModels.length === 0) { + return Promise.resolve(); } - ), + + return outputFile(getOutputFilename(type), typeModels); + }), // outputFile(getOutputFilename(`all-${isMobile ? 'm' : 'd'}`), rowsByGpu), ]); } -})().catch((err): void => { +})().catch((err) => { throw err; }); -// eslint-disable-next-line @typescript-eslint/no-explicit-any -const outputFile = async (name: string, content: any): Promise => { +const outputFile = async (name: string, content: any) => { const file = `./benchmarks/${name}`; const data = JSON.stringify(content); await fs.promises.writeFile(file, data); diff --git a/src/index.ts b/src/index.ts index 0c9f64c..61ac10e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,11 +9,17 @@ import { deviceInfo, isSSR } from './internal/deviceInfo'; import { deobfuscateRenderer } from './internal/deobfuscateRenderer'; // Types -import type { IGetGPUTier, TModelEntry, TTierResult, TTierType } from './types'; +import type { + GetGPUTier, + ModelEntry, + TierResult, + TierType, + ModelEntryScreen, +} from './types'; const debug = false ? console.log : undefined; -const queryCache: { [k: string]: Promise } = {}; +const queryCache: { [k: string]: Promise } = {}; export const getGPUTier = async ({ mobileTiers = [0, 15, 30, 60], @@ -28,17 +34,15 @@ export const getGPUTier = async ({ glContext, failIfMajorPerformanceCaveat = true, benchmarksURL = '/benchmarks', -}: IGetGPUTier = {}): Promise => { +}: GetGPUTier = {}): Promise => { const MODEL_INDEX = 0; const queryBenchmarks = async ( - loadBenchmarks = async ( - file: string - ): Promise => { + loadBenchmarks = async (file: string) => { try { - const data = await fetch(`${benchmarksURL}/${file}`).then( + const data: ModelEntry[] = await fetch(`${benchmarksURL}/${file}`).then( // eslint-disable-next-line @typescript-eslint/no-explicit-any - (response): Promise => response.json() + (response) => response.json() ); return data; @@ -87,7 +91,7 @@ export const getGPUTier = async ({ const benchmarkFile = `${isMobile ? 'm' : 'd'}-${type}.json`; - const benchmark: Promise = (queryCache[ + const benchmark: Promise = (queryCache[ benchmarkFile ] = queryCache[benchmarkFile] || loadBenchmarks(benchmarkFile)); @@ -101,21 +105,19 @@ export const getGPUTier = async ({ const isApple = type === 'apple'; - let matched: TModelEntry[] = benchmarks.filter( - ([, modelVersion]): boolean => modelVersion === version + let matched: ModelEntry[] = benchmarks.filter( + ([, modelVersion]) => modelVersion === version ); debug?.( `found ${matched.length} matching entries using version '${version}':`, - matched.map(([model]): string => model) + matched.map(([model]) => model) ); // If nothing matched, try comparing model names: if (!matched.length) { - matched = benchmarks.filter( - ([model]): boolean => model.indexOf(renderer) > -1 - ); + matched = benchmarks.filter(([model]) => model.indexOf(renderer) > -1); debug?.( `found ${matched.length} matching entries comparing model names`, @@ -136,10 +138,9 @@ export const getGPUTier = async ({ count > 1 ? matched .map( - (match): readonly [TModelEntry, number] => - [match, leven(renderer, match[MODEL_INDEX])] as const + (match) => [match, leven(renderer, match[MODEL_INDEX])] as const ) - .sort(([, a], [, b]): number => a - b)[0][MODEL_INDEX] + .sort(([, a], [, b]) => a - b)[0][MODEL_INDEX] : matched[0]; debug?.( @@ -148,17 +149,19 @@ export const getGPUTier = async ({ ); let minDistance = Number.MAX_VALUE; - let closest: [number, number, number, string]; + let closest: ModelEntryScreen; const { devicePixelRatio } = window; const pixelCount = screenSize.width * devicePixelRatio * (screenSize.height * devicePixelRatio); - if (isApple) { + // Extra step for apple devices to distinguish between ipad and iphone + // devices (which often share screen resolutions): + if (isApple && isMobile) { fpsesByPixelCount = fpsesByPixelCount.filter( - ([, , , device]): boolean => - device.indexOf(isIpad ? 'ipad' : 'iphone') > -1 + ([, , , device]) => + (device?.indexOf(isIpad ? 'ipad' : 'iphone') ?? -1) > -1 ); } @@ -182,11 +185,11 @@ export const getGPUTier = async ({ const toResult = ( tier: number, - type: TTierType, + type: TierType, fps?: number, gpu?: string, device?: string - ): TTierResult => ({ + ) => ({ device, fps, gpu, @@ -237,8 +240,7 @@ export const getGPUTier = async ({ results.length === 1 ? results[0] : results.sort( - ([aDis = Number.MAX_VALUE], [bDis = Number.MAX_VALUE]): number => - aDis - bDis + ([aDis = Number.MAX_VALUE], [bDis = Number.MAX_VALUE]) => aDis - bDis )[0]; if (result.length === 0) { diff --git a/src/internal/deobfuscateAppleGpu.ts b/src/internal/deobfuscateAppleGpu.ts index eb6dabc..b2ea3d9 100644 --- a/src/internal/deobfuscateAppleGpu.ts +++ b/src/internal/deobfuscateAppleGpu.ts @@ -24,7 +24,7 @@ export const deobfuscateAppleGpu = ( gl: WebGLRenderingContext, renderer: string, isMobileTier: boolean -): string[] => { +) => { let renderers = [renderer]; if (isMobileTier) { diff --git a/src/internal/deobfuscateRenderer.ts b/src/internal/deobfuscateRenderer.ts index 0fe540b..eab365b 100644 --- a/src/internal/deobfuscateRenderer.ts +++ b/src/internal/deobfuscateRenderer.ts @@ -5,7 +5,7 @@ export const deobfuscateRenderer = ( gl: WebGLRenderingContext, renderer: string, isMobileTier: boolean -): string[] => +) => renderer === 'apple gpu' ? deobfuscateAppleGpu(gl, renderer, isMobileTier) : [renderer]; diff --git a/src/internal/deviceInfo.ts b/src/internal/deviceInfo.ts index 933ce5d..6c0e996 100644 --- a/src/internal/deviceInfo.ts +++ b/src/internal/deviceInfo.ts @@ -1,10 +1,6 @@ export const isSSR = typeof window === 'undefined'; -export const deviceInfo = ((): { - isMobile?: boolean; - isSafari12?: boolean; - isIpad?: boolean; -} => { +export const deviceInfo = (() => { if (isSSR) { return {}; } @@ -23,6 +19,7 @@ export const deviceInfo = ((): { const isAndroid = /android/i.test(userAgent); return { + isIOS, isIpad, isMobile: isAndroid || isIOS || isIpad, isSafari12: /Version\/12.+Safari/.test(userAgent), diff --git a/src/internal/getGPUVersion.ts b/src/internal/getGPUVersion.ts index 84132fa..fda43b6 100644 --- a/src/internal/getGPUVersion.ts +++ b/src/internal/getGPUVersion.ts @@ -1,4 +1,4 @@ -export const getGPUVersion = (model: string): string => { +export const getGPUVersion = (model: string) => { model = model.replace(/\([^\)]+\)/, ''); const matches = diff --git a/src/internal/getWebGLContext.ts b/src/internal/getWebGLContext.ts index c5e3db0..def58e7 100644 --- a/src/internal/getWebGLContext.ts +++ b/src/internal/getWebGLContext.ts @@ -1,7 +1,7 @@ export const getWebGLContext = ( isSafari12?: boolean, failIfMajorPerformanceCaveat = true -): WebGLRenderingContext | undefined => { +) => { const attributes: { alpha: boolean; antialias: boolean; diff --git a/src/types/index.ts b/src/types/index.ts index 427e5b1..c2282b5 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,4 +1,4 @@ -export interface IGetGPUTier { +export interface GetGPUTier { glContext?: WebGLRenderingContext | WebGL2RenderingContext; failIfMajorPerformanceCaveat?: boolean; mobileTiers?: number[]; @@ -8,29 +8,26 @@ export interface IGetGPUTier { isIpad?: boolean; isMobile?: boolean; screenSize?: { width: number; height: number }; - loadBenchmarks?: (file: string) => Promise; + loadBenchmarks?: (file: string) => Promise; }; benchmarksURL?: string; } -export type TTierType = +export type TierType = | 'WEBGL_UNSUPPORTED' | 'BLACKLISTED' | 'FALLBACK' | 'BENCHMARK'; -export type TTierResult = { +export type TierResult = { tier: number; - type: TTierType; + type: TierType; isMobile: boolean; fps?: number; gpu?: string; device?: string; }; -export type TModelEntry = [ - string, - string, - 0 | 1, - [number, number, number, string][] -]; +export type ModelEntryScreen = [number, number, number, string | undefined]; + +export type ModelEntry = [string, string, 0 | 1, ModelEntryScreen[]]; diff --git a/test/index.test.ts b/test/index.test.ts index 39ce622..7c76bb8 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -3,7 +3,7 @@ import { RENDERER_MOBILE, RENDERER_TABLET, RENDERER_DESKTOP } from './data'; // Application import { getGPUTier } from '../src/index'; -import { TModelEntry, TTierResult } from '../src/types'; +import { ModelEntry, TierResult } from '../src/types'; const isDebug = false; @@ -15,30 +15,28 @@ const getTier = ({ isMobile?: boolean; renderer?: string; isIpad?: boolean; -}): Promise => +}) => getGPUTier({ desktopTiers: [0, 15, 30, 60], mobileTiers: [0, 15, 30, 60], override: { isIpad, isMobile, - loadBenchmarks: async ( - file: string - ): Promise => + loadBenchmarks: async (file: string): Promise => (await import(`../benchmarks/${file}`)).default, renderer, }, }); [RENDERER_MOBILE, RENDERER_TABLET, RENDERER_DESKTOP].forEach( - (renderers: string[]): void => { + (renderers: string[]) => { testRenders(renderers, renderers !== RENDERER_DESKTOP); } ); const topTierDesktop = 'ANGLE (NVIDIA GeForce RTX 2080 Ti Direct3D11 vs_5_0 ps_5_0)'; -test(`Top tier desktop: ${topTierDesktop}`, async (): Promise => { +test(`Top tier desktop: ${topTierDesktop}`, async () => { expectGPUResults( { isMobile: false, @@ -55,7 +53,7 @@ test(`Top tier desktop: ${topTierDesktop}`, async (): Promise => { const bottomTierDesktop = 'ANGLE (AMD Radeon(TM) HD 8280E Direct3D11 vs_5_0 ps_5_0)'; -test(`Bottom tier desktop: ${bottomTierDesktop}`, async (): Promise => { +test(`Bottom tier desktop: ${bottomTierDesktop}`, async () => { expectGPUResults( { isMobile: false, @@ -205,10 +203,8 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async (): Promise => { renderer: 'Mali-G51', }, }, -].map(({ input, expected }): void => { - test(`${input.renderer} should find ${expected.gpu}`, async (): Promise< - void - > => { +].map(({ input, expected }) => { + test(`${input.renderer} should find ${expected.gpu}`, async () => { expectGPUResults( { type: 'BENCHMARK', @@ -220,9 +216,9 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async (): Promise => { }); // expect FALLBACK results: -([['this renderer does not exist', true]] as [string, boolean][]).map( - ([renderer, isMobile]: [renderer: string, isMobile: boolean]): void => { - test(`${renderer} should return FALLBACK`, async (): Promise => { +[['this renderer does not exist', true] as const].map( + ([renderer, isMobile]) => { + test(`${renderer} should return FALLBACK`, async () => { expectGPUResults( { gpu: undefined, @@ -239,12 +235,9 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async (): Promise => { ); // expect BLACKLISTED results: -([['ANGLE (ATI Radeon HD 5670 Direct3D11 vs_5_0 ps_5_0)', false]] as [ - string, - boolean -][]).map( - ([renderer, isMobile]: [renderer: string, isMobile: boolean]): void => { - test(`${renderer} should return BLACKLISTED`, async (): Promise => { +[['ANGLE (ATI Radeon HD 5670 Direct3D11 vs_5_0 ps_5_0)', false] as const].map( + ([renderer, isMobile]) => { + test(`${renderer} should return BLACKLISTED`, async () => { expectGPUResults( { isMobile, @@ -260,9 +253,9 @@ test(`Bottom tier desktop: ${bottomTierDesktop}`, async (): Promise => { ); const expectGPUResults = ( - expected: Partial, - result: TTierResult -): void => { + expected: Partial, + result: TierResult +) => { if (expected.type) { expect(result.type).toBe(expected.type); } @@ -280,41 +273,37 @@ const expectGPUResults = ( } }; -function testRenders(deviceType: string[], mobileDevice = false): void { - deviceType.forEach( - async (renderer: string): Promise => { - test(`${renderer} -> GPUTier returns a valid tier`, async (): Promise< - void - > => { - const input = { - isIpad: /apple.+x/i.test(renderer), - isMobile: mobileDevice, - renderer, - }; +function testRenders(deviceType: string[], mobileDevice = false) { + deviceType.forEach(async (renderer: string) => { + test(`${renderer} -> GPUTier returns a valid tier`, async () => { + const input = { + isIpad: /apple.+x/i.test(renderer), + isMobile: mobileDevice, + renderer, + }; - const result = await getTier(input); - const jsonResult = JSON.stringify(result, null, 2); - const { type, tier } = result; + const result = await getTier(input); + const jsonResult = JSON.stringify(result, null, 2); + const { type, tier } = result; - if (isDebug) { - console.log( - `${tier === 0 ? `TIER 0` : type} -> Input: ${JSON.stringify( - input, - null, - 2 - )} - Output: ${jsonResult}` - ); - } + if (isDebug) { + console.log( + `${tier === 0 ? `TIER 0` : type} -> Input: ${JSON.stringify( + input, + null, + 2 + )} - Output: ${jsonResult}` + ); + } - expect([0, 1, 2, 3]).toContain(tier); + expect([0, 1, 2, 3]).toContain(tier); - expect([ - 'WEBGL_UNSUPPORTED', - 'BLACKLISTED', - 'FALLBACK', - 'BENCHMARK', - ]).toContain(type); - }); - } - ); + expect([ + 'WEBGL_UNSUPPORTED', + 'BLACKLISTED', + 'FALLBACK', + 'BENCHMARK', + ]).toContain(type); + }); + }); } From 4c0c1446e111c543264fd8a1a209f8a1e5718d23 Mon Sep 17 00:00:00 2001 From: Tim van Scherpenzeel Date: Thu, 8 Oct 2020 11:57:55 +0200 Subject: [PATCH 2/5] Update update_benchmarks.ts --- scripts/update_benchmarks.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/update_benchmarks.ts b/scripts/update_benchmarks.ts index 887e149..61eea58 100755 --- a/scripts/update_benchmarks.ts +++ b/scripts/update_benchmarks.ts @@ -30,6 +30,8 @@ type BenchmarkRow = { resolution: string; }; +type Optional = Pick, K> & Omit; + (async () => { const browser = await puppeteer.launch({ headless: true }); const benchmarks = await getBenchmarks(); @@ -43,7 +45,6 @@ type BenchmarkRow = { const page = await browser.newPage(); await page.goto(BENCHMARK_URL, { waitUntil: 'networkidle2' }); - type Optional = Pick, K> & Omit; return await page.evaluate((): BenchmarkRow[] => { const { From bf8868d0637c2e178b930467f669ac2292a4f525 Mon Sep 17 00:00:00 2001 From: Tim van Scherpenzeel Date: Thu, 8 Oct 2020 12:18:54 +0200 Subject: [PATCH 3/5] clean up --- scripts/update_benchmarks.ts | 83 ++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 41 deletions(-) diff --git a/scripts/update_benchmarks.ts b/scripts/update_benchmarks.ts index 61eea58..16a4376 100755 --- a/scripts/update_benchmarks.ts +++ b/scripts/update_benchmarks.ts @@ -21,6 +21,47 @@ const types = [ 'geforce', ]; +// GPU BLACKLIST +// https://wiki.mozilla.org/Blocklisting/Blocked_Graphics_Drivers +// https://www.khronos.org/webgl/wiki/BlacklistsAndWhitelists +// https://chromium.googlesource.com/chromium/src/+/master/gpu/config/software_rendering_list.json +// https://chromium.googlesource.com/chromium/src/+/master/gpu/config/gpu_driver_bug_list.json +const blacklistedModels = [ + 'radeon hd 6970m', + 'radeon hd 6770m', + 'radeon hd 6490m', + 'radeon hd 6630m', + 'radeon hd 6750m', + 'radeon hd 5750', + 'radeon hd 5670', + 'radeon hd 4850', + 'radeon hd 4870', + 'radeon hd 4670', + 'geforce 9400m', + 'geforce 320m', + 'geforce 330m', + 'geforce gt 130', + 'geforce gt 120', + 'geforce gtx 285', + 'geforce 8600', + 'geforce 9600m', + 'geforce 9400m', + 'geforce 8800 gs', + 'geforce 8800 gt', + 'quadro fx 5', + 'quadro fx 4', + 'radeon hd 2600', + 'radeon hd 2400', + 'radeon r9 200', + 'mali-4', + 'mali-3', + 'mali-2', + 'google swiftshader', + 'sgx543', + 'legacy', + 'sgx 543', +]; + type BenchmarkRow = { date: string; device: string; @@ -68,6 +109,7 @@ type Optional = Pick, K> & Omit; formFactorLookup: string[]; formFactor: number[]; }; + return gpuName .map( (gpuIndex, index): Optional => ({ @@ -171,44 +213,3 @@ const outputFile = async (name: string, content: any) => { await fs.promises.writeFile(file, data); console.log(`Exported ${file}`); }; - -// GPU BLACKLIST -// https://wiki.mozilla.org/Blocklisting/Blocked_Graphics_Drivers -// https://www.khronos.org/webgl/wiki/BlacklistsAndWhitelists -// https://chromium.googlesource.com/chromium/src/+/master/gpu/config/software_rendering_list.json -// https://chromium.googlesource.com/chromium/src/+/master/gpu/config/gpu_driver_bug_list.json -const blacklistedModels = [ - 'radeon hd 6970m', - 'radeon hd 6770m', - 'radeon hd 6490m', - 'radeon hd 6630m', - 'radeon hd 6750m', - 'radeon hd 5750', - 'radeon hd 5670', - 'radeon hd 4850', - 'radeon hd 4870', - 'radeon hd 4670', - 'geforce 9400m', - 'geforce 320m', - 'geforce 330m', - 'geforce gt 130', - 'geforce gt 120', - 'geforce gtx 285', - 'geforce 8600', - 'geforce 9600m', - 'geforce 9400m', - 'geforce 8800 gs', - 'geforce 8800 gt', - 'quadro fx 5', - 'quadro fx 4', - 'radeon hd 2600', - 'radeon hd 2400', - 'radeon r9 200', - 'mali-4', - 'mali-3', - 'mali-2', - 'google swiftshader', - 'sgx543', - 'legacy', - 'sgx 543', -]; From 4e11540e3cf5e6f15cf18e35f1f143c1b433d316 Mon Sep 17 00:00:00 2001 From: Tim van Scherpenzeel Date: Thu, 8 Oct 2020 12:48:43 +0200 Subject: [PATCH 4/5] Update LICENSE --- LICENSE | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LICENSE b/LICENSE index 4a9fbfc..844f03d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Tim van Scherpenzeel +Copyright (c) 2020 Tim van Scherpenzeel Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal From 5d5e77d1fab4d0843070185cd50f85f9b59cff59 Mon Sep 17 00:00:00 2001 From: puckey Date: Thu, 8 Oct 2020 14:41:44 +0200 Subject: [PATCH 5/5] avoid exporting isIOS --- src/internal/deviceInfo.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/internal/deviceInfo.ts b/src/internal/deviceInfo.ts index 6c0e996..0e940ea 100644 --- a/src/internal/deviceInfo.ts +++ b/src/internal/deviceInfo.ts @@ -19,7 +19,6 @@ export const deviceInfo = (() => { const isAndroid = /android/i.test(userAgent); return { - isIOS, isIpad, isMobile: isAndroid || isIOS || isIpad, isSafari12: /Version\/12.+Safari/.test(userAgent),