Skip to content

Commit

Permalink
Speddup (#436)
Browse files Browse the repository at this point in the history
* feat: added `Array.toArray` & optimization
* chore: updated /lib
* refactor: review & improve perfomance
* fix: fixed bugs after refactoring
* feat: added wrapWithSuspending
* chore: removed redundant async contexts
  • Loading branch information
kobezzza authored Oct 1, 2024
1 parent 6385e93 commit ee6eedf
Show file tree
Hide file tree
Showing 166 changed files with 8,275 additions and 5,575 deletions.
4 changes: 3 additions & 1 deletion .tsconfig
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@
"strictPropertyInitialization": true,

"noImplicitOverride": true,
"importsNotUsedAsValues": "error"
"importsNotUsedAsValues": "error",

"isolatedModules": false
},

"include": [
Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,24 @@ Changelog
_Note: Gaps between patch versions are faulty, broken or test releases._

## v4.0.0-beta.?? (2024-??-??)

#### :boom: Breaking Change

* `core/async`:
* Moved code from `V4/Client`
* Removed deprecated API and refactored internal structures

#### :rocket: New Feature

* Added a new method `Array.toArray` `core/prelude`
* Added support for baked symbols `core/symbol`

#### :house: Internal

* Conduct refactoring and optimization of the module `core/async`
* Various performance optimizations

## v4.0.0-alpha.46 (2024-09-25)

#### :boom: breaking change
Expand Down
88 changes: 48 additions & 40 deletions lib/core/async/const.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,43 +5,51 @@
* Released under the MIT license
* https://github.com/V4Fire/Core/blob/master/LICENSE
*/
export declare const namespaces: {
[x: number]: number;
readonly proxy: "proxy";
readonly proxyPromise: "proxyPromise";
readonly promise: "promise";
readonly iterable: "iterable";
readonly request: "request";
readonly idleCallback: "idleCallback";
readonly idleCallbackPromise: "idleCallbackPromise";
readonly timeout: "timeout";
readonly timeoutPromise: "timeoutPromise";
readonly interval: "interval";
readonly intervalPromise: "intervalPromise";
readonly immediate: "immediate";
readonly immediatePromise: "immediatePromise";
readonly worker: "worker";
readonly eventListener: "eventListener";
readonly eventListenerPromise: "eventListenerPromise";
},
/** @deprecated */
linkNamesDictionary: {
[x: number]: number;
readonly proxy: "proxy";
readonly proxyPromise: "proxyPromise";
readonly promise: "promise";
readonly iterable: "iterable";
readonly request: "request";
readonly idleCallback: "idleCallback";
readonly idleCallbackPromise: "idleCallbackPromise";
readonly timeout: "timeout";
readonly timeoutPromise: "timeoutPromise";
readonly interval: "interval";
readonly intervalPromise: "intervalPromise";
readonly immediate: "immediate";
readonly immediatePromise: "immediatePromise";
readonly worker: "worker";
readonly eventListener: "eventListener";
readonly eventListenerPromise: "eventListenerPromise";
};
export declare type NamespacesDictionary = typeof namespaces;
export declare enum Namespaces {
proxy = 0,
promise = 1,
iterable = 2,
request = 3,
idleCallback = 4,
timeout = 5,
interval = 6,
immediate = 7,
worker = 8,
eventListener = 9,
animationFrame = 10,
proxyPromise = 11,
timeoutPromise = 12,
intervalPromise = 13,
immediatePromise = 14,
idleCallbackPromise = 15,
animationFramePromise = 16,
eventListenerPromise = 17,
length = 18
}
export declare const enum PrimitiveNamespaces {
proxy = 0,
promise = 1,
iterable = 2,
request = 3,
idleCallback = 4,
timeout = 5,
interval = 6,
immediate = 7,
worker = 8,
eventListener = 9,
animationFrame = 10,
length = 11
}
export declare const enum PromiseNamespaces {
first = 10,
proxyPromise = 11,
timeoutPromise = 12,
intervalPromise = 13,
immediatePromise = 14,
idleCallbackPromise = 15,
animationFramePromise = 16,
eventListenerPromise = 17,
length = 18
}
export declare const usedNamespaces: any[];
export declare const namespacesCache: any[];
63 changes: 57 additions & 6 deletions lib/core/async/const.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,60 @@
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.namespaces = exports.linkNamesDictionary = void 0;
var _interface = require("../../core/async/interface");
const namespaces = Object.convertEnumToDict(_interface.Namespaces),
linkNamesDictionary = namespaces;
exports.linkNamesDictionary = linkNamesDictionary;
exports.namespaces = namespaces;
exports.usedNamespaces = exports.namespacesCache = exports.PromiseNamespaces = exports.PrimitiveNamespaces = exports.Namespaces = void 0;
let Namespaces = function (Namespaces) {
Namespaces[Namespaces["proxy"] = 0] = "proxy";
Namespaces[Namespaces["promise"] = 1] = "promise";
Namespaces[Namespaces["iterable"] = 2] = "iterable";
Namespaces[Namespaces["request"] = 3] = "request";
Namespaces[Namespaces["idleCallback"] = 4] = "idleCallback";
Namespaces[Namespaces["timeout"] = 5] = "timeout";
Namespaces[Namespaces["interval"] = 6] = "interval";
Namespaces[Namespaces["immediate"] = 7] = "immediate";
Namespaces[Namespaces["worker"] = 8] = "worker";
Namespaces[Namespaces["eventListener"] = 9] = "eventListener";
Namespaces[Namespaces["animationFrame"] = 10] = "animationFrame";
Namespaces[Namespaces["proxyPromise"] = 11] = "proxyPromise";
Namespaces[Namespaces["timeoutPromise"] = 12] = "timeoutPromise";
Namespaces[Namespaces["intervalPromise"] = 13] = "intervalPromise";
Namespaces[Namespaces["immediatePromise"] = 14] = "immediatePromise";
Namespaces[Namespaces["idleCallbackPromise"] = 15] = "idleCallbackPromise";
Namespaces[Namespaces["animationFramePromise"] = 16] = "animationFramePromise";
Namespaces[Namespaces["eventListenerPromise"] = 17] = "eventListenerPromise";
Namespaces[Namespaces["length"] = 18] = "length";
return Namespaces;
}({});
exports.Namespaces = Namespaces;
let PrimitiveNamespaces = function (PrimitiveNamespaces) {
PrimitiveNamespaces[PrimitiveNamespaces["proxy"] = 0] = "proxy";
PrimitiveNamespaces[PrimitiveNamespaces["promise"] = 1] = "promise";
PrimitiveNamespaces[PrimitiveNamespaces["iterable"] = 2] = "iterable";
PrimitiveNamespaces[PrimitiveNamespaces["request"] = 3] = "request";
PrimitiveNamespaces[PrimitiveNamespaces["idleCallback"] = 4] = "idleCallback";
PrimitiveNamespaces[PrimitiveNamespaces["timeout"] = 5] = "timeout";
PrimitiveNamespaces[PrimitiveNamespaces["interval"] = 6] = "interval";
PrimitiveNamespaces[PrimitiveNamespaces["immediate"] = 7] = "immediate";
PrimitiveNamespaces[PrimitiveNamespaces["worker"] = 8] = "worker";
PrimitiveNamespaces[PrimitiveNamespaces["eventListener"] = 9] = "eventListener";
PrimitiveNamespaces[PrimitiveNamespaces["animationFrame"] = 10] = "animationFrame";
PrimitiveNamespaces[PrimitiveNamespaces["length"] = 11] = "length";
return PrimitiveNamespaces;
}({});
exports.PrimitiveNamespaces = PrimitiveNamespaces;
let PromiseNamespaces = function (PromiseNamespaces) {
PromiseNamespaces[PromiseNamespaces["first"] = 10] = "first";
PromiseNamespaces[PromiseNamespaces["proxyPromise"] = 11] = "proxyPromise";
PromiseNamespaces[PromiseNamespaces["timeoutPromise"] = 12] = "timeoutPromise";
PromiseNamespaces[PromiseNamespaces["intervalPromise"] = 13] = "intervalPromise";
PromiseNamespaces[PromiseNamespaces["immediatePromise"] = 14] = "immediatePromise";
PromiseNamespaces[PromiseNamespaces["idleCallbackPromise"] = 15] = "idleCallbackPromise";
PromiseNamespaces[PromiseNamespaces["animationFramePromise"] = 16] = "animationFramePromise";
PromiseNamespaces[PromiseNamespaces["eventListenerPromise"] = 17] = "eventListenerPromise";
PromiseNamespaces[PromiseNamespaces["length"] = 18] = "length";
return PromiseNamespaces;
}({});
exports.PromiseNamespaces = PromiseNamespaces;
const usedNamespaces = new Array(Namespaces.length).fill(false);
exports.usedNamespaces = usedNamespaces;
const namespacesCache = new Array(Namespaces.length).fill(null);
exports.namespacesCache = namespacesCache;
36 changes: 36 additions & 0 deletions lib/core/async/core/api.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*!
* V4Fire Core
* https://github.com/V4Fire/Core
*
* Released under the MIT license
* https://github.com/V4Fire/Core/blob/master/LICENSE
*/
import Super from '../../../core/async/core/core';
import type { ClearOptions } from '../../../core/async/interface';
export default class Async<CTX extends object = Async<any>> extends Super<CTX> {
/**
* Clears all asynchronous tasks
* @param [opts] - additional options for the operation
*/
clearAll(opts?: ClearOptions): this;
/**
* Mutes all asynchronous tasks
* @param [opts] - additional options for the operation
*/
muteAll(opts?: ClearOptions): this;
/**
* Unmutes all asynchronous tasks
* @param [opts] - additional options for the operation
*/
unmuteAll(opts?: ClearOptions): this;
/**
* Suspends all asynchronous tasks
* @param [opts] - additional options for the operation
*/
suspendAll(opts?: ClearOptions): this;
/**
* Unsuspends all asynchronous tasks
* @param [opts] - additional options for the operation
*/
unsuspendAll(opts?: ClearOptions): this;
}
79 changes: 79 additions & 0 deletions lib/core/async/core/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var _core = _interopRequireDefault(require("../../../core/async/core/core"));
var _const = require("../../../core/async/core/const");
class Async extends _core.default {
clearAll(opts) {
this.usedNamespaces.forEach((used, i) => {
if (!used) {
return;
}
const key = this.Namespaces[i],
alias = `clear-${key}`.camelize(false);
if (Object.isFunction(this[alias])) {
this[alias](opts);
} else if (!_const.isPromisifyNamespace.test(i)) {
throw new ReferenceError(`The method "${alias}" is not defined`);
}
});
return this;
}
muteAll(opts) {
this.usedNamespaces.forEach((used, i) => {
if (!used) {
return;
}
const key = this.Namespaces[i],
alias = `mute-${key}`.camelize(false);
if (!_const.isPromisifyNamespace.test(i) && Object.isFunction(this[alias])) {
this[alias](opts);
}
});
return this;
}
unmuteAll(opts) {
this.usedNamespaces.forEach((used, i) => {
if (!used) {
return;
}
const key = this.Namespaces[i],
alias = `unmute-${key}`.camelize(false);
if (!_const.isPromisifyNamespace.test(i) && Object.isFunction(this[alias])) {
this[alias](opts);
}
});
return this;
}
suspendAll(opts) {
this.usedNamespaces.forEach((used, i) => {
if (!used) {
return;
}
const key = this.Namespaces[i],
alias = `suspend-${key}`.camelize(false);
if (!_const.isPromisifyNamespace.test(i) && Object.isFunction(this[alias])) {
this[alias](opts);
}
});
return this;
}
unsuspendAll(opts) {
this.usedNamespaces.forEach((used, i) => {
if (!used) {
return;
}
const key = this.Namespaces[i],
alias = `unsuspend-${key}`.camelize(false);
if (!_const.isPromisifyNamespace.test(i) && Object.isFunction(this[alias])) {
this[alias](opts);
}
});
return this;
}
}
exports.default = Async;
15 changes: 15 additions & 0 deletions lib/core/async/core/const.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*!
* V4Fire Core
* https://github.com/V4Fire/Core
*
* Released under the MIT license
* https://github.com/V4Fire/Core/blob/master/LICENSE
*/
import { Namespaces } from '../../../core/async/const';
export declare const asyncCounter: unique symbol;
export declare const isZombieGroup: {
test(group: string): boolean;
};
export declare const isPromisifyNamespace: {
test(namespace: Namespaces): boolean;
};
21 changes: 21 additions & 0 deletions lib/core/async/core/const.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use strict";

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.isZombieGroup = exports.isPromisifyNamespace = exports.asyncCounter = void 0;
var _const = require("../../../core/async/const");
const asyncCounter = Symbol('Async counter id');
exports.asyncCounter = asyncCounter;
const isZombieGroup = {
test(group) {
return group.includes(':zombie');
}
};
exports.isZombieGroup = isZombieGroup;
const isPromisifyNamespace = {
test(namespace) {
return namespace > _const.PromiseNamespaces.first;
}
};
exports.isPromisifyNamespace = isPromisifyNamespace;
Loading

0 comments on commit ee6eedf

Please sign in to comment.