mirror of
https://github.com/vale981/tridactyl
synced 2025-03-04 17:11:40 -05:00
Metadata Types: Use a single type instance where it makes sense
One of the possible problems of #1184 (firefox freezing periodically with Tridactyl enabled) is that Tridactyl uses too much RAM, which could cause Firefox to attempt to GC it from time to time. One easy optimisation to try to reduce this problem is to use singletons for metadata when possible (VoidType, AnyType...). According to my measurements, this saves the allocation of 933 objects, which amounted to ~0.03MB. Multiply this by 40 tabs and you get about 1.20MB saved, the space of a whole 1980-era floppy disk.
This commit is contained in:
parent
7e21d64025
commit
a808e9e742
5 changed files with 10 additions and 5 deletions
|
@ -1,12 +1,13 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class AnyType implements Type {
|
||||
static instance = new AnyType()
|
||||
kind = "any"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
return "new AnyType()"
|
||||
return "AnyType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class BooleanType implements Type {
|
||||
static instance = new BooleanType()
|
||||
kind = "boolean"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
return "new BooleanType()"
|
||||
return "BooleanType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class NumberType implements Type {
|
||||
static instance = new NumberType()
|
||||
kind = "number"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
return "new NumberType()"
|
||||
return "NumberType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class StringType implements Type {
|
||||
static instance = new StringType()
|
||||
kind = "string"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
return "new StringType()"
|
||||
return "StringType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
|
|
@ -1,12 +1,13 @@
|
|||
import { Type } from "./Type"
|
||||
|
||||
export class VoidType implements Type {
|
||||
static instance = new VoidType()
|
||||
kind = "void"
|
||||
|
||||
constructor() {}
|
||||
|
||||
toConstructor() {
|
||||
return "new VoidType()"
|
||||
return "VoidType.instance"
|
||||
}
|
||||
|
||||
toString() {
|
||||
|
|
Loading…
Add table
Reference in a new issue