Skip to content

Commit

Permalink
perf: reducing GC overhead
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon committed Feb 1, 2025
1 parent 18ae8b4 commit b1dcc98
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 47 deletions.
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.4",
"@rollup/plugin-typescript": "^12.1.0",
"@rollup/plugin-typescript": "^12.1.2",
"@types/chai": "^4.3.16",
"@types/jsdom": "^21.1.7",
"@types/mocha": "^10.0.8",
"@types/mocha": "^10.0.10",
"@types/sinon": "^17.0.3",
"c8": "^10.1.2",
"c8": "^10.1.3",
"chai": "^4.5.0",
"jsdom": "^25.0.1",
"mocha": "^10.7.3",
"rollup": "^4.24.0",
"mocha": "^10.8.2",
"rollup": "^4.34.0",
"sinon": "^19.0.2",
"ts-node": "^10.9.2",
"tslib": "^2.7.0",
"typescript": "^5.6.2"
"tslib": "^2.8.1",
"typescript": "^5.7.3"
},
"repository": {
"type": "git",
Expand Down
8 changes: 5 additions & 3 deletions src/lib/engine.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import type Anime from "../Anime";
import type { KeyFrameProp } from "../types";
import penner from "./penner";

const pennerFn = penner();

// 目前仅支持translate
const validTransform = ["translateX", "translateY", "translateZ"];

Expand Down Expand Up @@ -138,7 +140,7 @@ export default (anime: Anime) => {
} = (dest as KeyFrameProp)[i - 1];
origin = i <= 1 ? origin : (dest as KeyFrameProp)[i - 2].value;
if (current <= start + duration + startTimeStamp) {
elapsed = penner()[easing]()(
elapsed = pennerFn[easing]()(
(current - start - startTimeStamp) / duration
);

Expand All @@ -151,7 +153,7 @@ export default (anime: Anime) => {
// 支持 {value: 1, duration: 500, easing: 'linear'}
const { value, duration, easing = anime.easing } = dest;
if (current <= start + duration) {
elapsed = penner()[easing]()((current - start) / duration);
elapsed = pennerFn[easing]()((current - start) / duration);
change(target, origin, elapsed, value, key);
} else if (final) {
change(target, origin, elapsed, value, key, final);
Expand Down Expand Up @@ -189,7 +191,7 @@ export default (anime: Anime) => {
anime.isPlay = false;
} else {
if (current >= start) {
const elapsed = penner()[anime.easing]()(
const elapsed = pennerFn[anime.easing]()(
(current - start) / anime.duration
);
if (isValid) changeAll(elapsed, current);
Expand Down
38 changes: 1 addition & 37 deletions test/penner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,196 +3,160 @@ const should = chai.should();
import penner from "../src/lib/penner";

describe("penner", () => {
const p = penner();
it("linear", () => {
const p = penner();
p.linear()(0.5).should.equal(0.5);
});

it("easeInSine", () => {
const p = penner();
p.easeInSine()(0.5).should.equal(0.2928932188134524);
});

it("easeOutSine", () => {
const p = penner();
p.easeOutSine()(0.5).should.equal(0.7071067811865476);
});

it("easeInOutSine", () => {
const p = penner();
p.easeInOutSine()(0.5).should.equal(0.5);
});

it("easeOutInSine", () => {
const p = penner();
p.easeOutInSine()(0.5).should.equal(0.5);
});

it("easeInQuad", () => {
const p = penner();
p.easeInQuad()(0.5).should.equal(0.25);
});

it("easeOutQuad", () => {
const p = penner();
p.easeOutQuad()(0.5).should.equal(0.75);
});

it("easeInOutQuad", () => {
const p = penner();
p.easeInOutQuad()(0.5).should.equal(0.5);
});

it("easeOutInQuad", () => {
const p = penner();
p.easeOutInQuad()(0.5).should.equal(0.5);
});

it("easeInCubic", () => {
const p = penner();
p.easeInCubic()(0.5).should.equal(0.125);
});

it("easeOutCubic", () => {
const p = penner();
p.easeOutCubic()(0.5).should.equal(0.875);
});

it("easeInOutCubic", () => {
const p = penner();
p.easeInOutCubic()(0.5).should.equal(0.5);
});

it("easeOutInCubic", () => {
const p = penner();
p.easeOutInCubic()(0.5).should.equal(0.5);
});

it("easeInQuart", () => {
const p = penner();
p.easeInQuart()(0.5).should.equal(0.0625);
});

it("easeOutQuart", () => {
const p = penner();
p.easeOutQuart()(0.5).should.equal(0.9375);
});

it("easeInOutQuart", () => {
const p = penner();
p.easeInOutQuart()(0.5).should.equal(0.5);
});

it("easeOutInQuart", () => {
const p = penner();
p.easeOutInQuart()(0.5).should.equal(0.5);
});

it("easeInQuint", () => {
const p = penner();
p.easeInQuint()(0.5).should.equal(0.03125);
});

it("easeOutQuint", () => {
const p = penner();
p.easeOutQuint()(0.5).should.equal(0.96875);
});

it("easeInOutQuint", () => {
const p = penner();
p.easeInOutQuint()(0.5).should.equal(0.5);
});

it("easeOutInQuint", () => {
const p = penner();
p.easeOutInQuint()(0.5).should.equal(0.5);
});

it("easeInExpo", () => {
const p = penner();
p.easeInExpo()(0.5).should.equal(0.03125);
});

it("easeOutExpo", () => {
const p = penner();
p.easeOutExpo()(0.5).should.equal(0.96875);
});

it("easeInOutExpo", () => {
const p = penner();
p.easeInOutExpo()(0.5).should.equal(0.5);
});

it("easeOutInExpo", () => {
const p = penner();
p.easeOutInExpo()(0.5).should.equal(0.5);
});

it("easeInCirc", () => {
const p = penner();
p.easeInCirc()(0.5).should.equal(0.1339745962155614);
});

it("easeOutCirc", () => {
const p = penner();
p.easeOutCirc()(0.5).should.equal(0.8660254037844386);
});

it("easeInOutCirc", () => {
const p = penner();
p.easeInOutCirc()(0.5).should.equal(0.5);
});

it("easeOutInCirc", () => {
const p = penner();
p.easeOutInCirc()(0.5).should.equal(0.5);
});

it.skip("easeInBack", () => {
// not real easeInBack
const p = penner();
p.easeInBack()(0.5).should.equal(-0.0876975);
});

it.skip("easeOutBack", () => {
// not real easeOutBack
const p = penner();
p.easeOutBack()(0.5).should.equal(1.0876975);
});

it("easeInOutBack", () => {
// not real easeInOutBack
const p = penner();
p.easeInOutBack()(0.5).should.equal(0.5);
});

it("easeOutInBack", () => {
// not real easeOutInBack
const p = penner();
p.easeOutInBack()(0.5).should.equal(0.5);
});

it.skip("easeInBounce", () => {
// not real easeInBounce
const p = penner();
p.easeInBounce()(0.5).should.equal(0.046875);
});

it.skip("easeOutBounce", () => {
// not real easeOutBounce
const p = penner();
p.easeOutBounce()(0.5).should.equal(0.953125);
});

it("easeInOutBounce", () => {
// not real easeInOutBounce
const p = penner();
p.easeInOutBounce()(0.5).should.equal(0.5);
});

it("easeOutInBounce", () => {
// not real easeOutInBounce
const p = penner();
p.easeOutInBounce()(0.5).should.equal(0.5);
});
});

0 comments on commit b1dcc98

Please sign in to comment.