Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize generated functions #288

Closed
samchon opened this issue Oct 31, 2022 · 1 comment
Closed

Optimize generated functions #288

samchon opened this issue Oct 31, 2022 · 1 comment
Assignees
Labels
enhancement New feature or request

Comments

@samchon
Copy link
Owner

samchon commented Oct 31, 2022

Until now, I've made typescript-json to gather generated functions into an Array.

However, such indirect access to a function makes inlining hard by V8 engine.

Therefore, declare generated function into main scope, then performance would be enhanced by function inlining.

Previous Code

exports.test_create_is_object_simple = (0, _test_is_1._test_is)(
    "simple object",
    ObjectSimple_1.ObjectSimple.generate,
    (input) => {
        const $io = [
            (input) =>
                "object" === typeof input.scale &&
                null !== input.scale &&
                $io[1](input.scale) &&
                "object" === typeof input.position &&
                null !== input.position &&
                $io[1](input.position) &&
                "object" === typeof input.rotate &&
                null !== input.rotate &&
                $io[1](input.rotate) &&
                "object" === typeof input.pivot &&
                null !== input.pivot &&
                $io[1](input.pivot),
            (input) =>
                "number" === typeof input.x &&
                "number" === typeof input.y &&
                "number" === typeof input.z,
        ];
        return "object" === typeof input && null !== input && $io[0](input);
    },
    ObjectSimple_1.ObjectSimple.SPOILERS,
);

Next Code

exports.test_create_is_object_simple = (0, _test_is_1._test_is)(
    "simple object",
    ObjectSimple_1.ObjectSimple.generate,
    (input) => {
        const $io0 = (input) =>
            "object" === typeof input.scale &&
            null !== input.scale &&
            $io1(input.scale) &&
            "object" === typeof input.position &&
            null !== input.position &&
            $io1(input.position) &&
            "object" === typeof input.rotate &&
            null !== input.rotate &&
            $io1(input.rotate) &&
            "object" === typeof input.pivot &&
            null !== input.pivot &&
            $io1(input.pivot);
        const $io1 = (input) =>
            "number" === typeof input.x &&
            "number" === typeof input.y &&
            "number" === typeof input.z;
        return "object" === typeof input && null !== input && $io0(input);
    },
    ObjectSimple_1.ObjectSimple.SPOILERS,
);
@samchon samchon added the enhancement New feature or request label Oct 31, 2022
@samchon samchon self-assigned this Oct 31, 2022
samchon pushed a commit that referenced this issue Oct 31, 2022
@samchon
Copy link
Owner Author

samchon commented Oct 31, 2022

is() function

image

AMD 5900HX

assertType() function (iterate)

image

AMD 5900HX

assertType() function (throw)

image

AMD 5900HX

validate() function

image

AMD 5900HX

equals() function

image

Intel i5-1135g7

assertEquals() function (iterate)

image

Intel i5-1135g7

assertEquals() function (throw)

image

Intel i5-1135g7

validateEquals() function

image

Intel i5-1135g7

optimization time

image

Intel i5-1135g7

stringify() function

image

Intel i5-1135g7

samchon added a commit that referenced this issue Oct 31, 2022
samchon added a commit that referenced this issue Oct 31, 2022
 Close #288, generated functions are optimized
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant