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

regression of performance: fps on the 'stars.nml' demo #40

Open
verpeteren opened this issue Dec 7, 2016 · 4 comments
Open

regression of performance: fps on the 'stars.nml' demo #40

verpeteren opened this issue Dec 7, 2016 · 4 comments
Assignees

Comments

@verpeteren
Copy link
Contributor

Around 2016/01/27 a demo application 'stars.nml' ran at about 60 fps.
Currently (2017/12/37) it seems to run at about 30fps.

A prelimanary investigation indicates that the loss of performance happens somewere before 2016/06/20.

<application framework="false" version="0.1">
<!--
/* -------------------------------------------------------------------------- */
/* MIT license                                          (c) 2016 Nidium, Inc. */
/* -------------------------------------------------------------------------- */
/* Permission is hereby granted, free of charge, to any person obtaining a    */
/* copy of this software and associated documentation files (the "Software"), */
/* to deal in the Software without restriction, including without limitation  */
/* the rights to use, copy, modify, merge, publish, distribute, sublicense,   */
/* and/or sell copies of the Software, and to permit persons to whom the      */
/* Software is furnished to do so, subject to the following conditions:       */
/*                                                                            */
/* The above copyright notice and this permission notice shall be included in */
/* all copies or substantial portions of the Software.                        */
/*                                                                            */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,   */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL    */
/* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING    */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER        */
/* DEALINGS IN THE SOFTWARE.                                                  */
/* -------------------------------------------------------------------------- */
-->
    <meta>
        <title>Test case</title>
        <viewport> 800x600</viewport>
        <version>1.0</version>
        <date>2012-03-15</date>
        <robots>index, follow</robots>
        <identifier>com.nidium.app.demos.stars</identifier>
        <author>Nidium Inc.</author>
    </meta>
    <assets>
        <script>
            var canvas = document.canvas;
            var ctx = canvas.getContext("2d");
            document.showFPS(true);

            var particule = function(ctx) {
                this.ctx = ctx;
                this.reset();

                this.sizes = {
                    halfWidth: canvas.width / 2,
                    halfHeight: canvas.height / 2
                }
            }

            particule.prototype.reset = function() {
                this.positions = {
                    x: 2 * (Math.random() - 0.5),
                    y: 2 * (Math.random() - 0.5),
                    z: 1
                }
            }

            particule.prototype.draw = function() {
                //this.ctx.save();
                this.ctx.fillStyle = "#FFF";

                this.positions.z -= 0.01;

                var x = (this.positions.x / this.positions.z) * this.sizes.halfWidth + this.sizes.halfWidth;
                var y = (this.positions.y / this.positions.z) * this.sizes.halfHeight + this.sizes.halfHeight;

                if (x <= 0 || x > canvas.width || y <= 0 || y > canvas.height) {
                    this.reset();
                }

                this.ctx.fillRect(x, y, 1, 1);

                //this.ctx.restore();
            }


            var stars = [];

            for (var i = 0; i < 4096*4; i++) {
                stars[i] = new particule(ctx);
            }


            function draw()
            {
                ctx.fillStyle = "#000";
                ctx.fillRect(0, 0, canvas.width, canvas.height);

                for (var i = 0; i < stars.length; i++) {
                    stars[i].draw();
                }

                window.requestAnimationFrame(draw);
            }

            draw();

            /*ctx.fillStyle = "blue";
            //ctx.fillRect(0, 0, 20, 20);
            console.log("default", ctx.fillStyle);

            var img = new Image();
            img.src = "./pattern.png";
            img.onload = function() {
                var pattern = ctx.createPattern(img, "repeat");
                ctx.fillStyle = pattern;

                console.log("Pattern set");
                console.log("New fillstyle", ctx.fillStyle);

                ctx.save();

                console.log("After save", ctx.fillStyle);
                ctx.fillRect(0, 0, 800, 800);

                ctx.fillStyle = "red";

                console.log("remove pattern", ctx.fillStyle);

                ctx.restore();

                ctx.fillStyle = "yellow";
                console.log("After restore", ctx.fillStyle);
            }*/

        </script>
    </assets>
</application>



@paraboul
Copy link
Member

paraboul commented Jan 10, 2017

This should be fixed by 1d4af80

Can you confirm?

@verpeteren
Copy link
Contributor Author

The stars.nml app starts with 60fps, as soon as the mouse moves (once) it drops to 30fps (and stays there).

...
Mouse move to 10
...

So it is an improvement, but unfortunately it is not quite solved yet.

@paraboul
Copy link
Member

@verpeteren debug build or normal build?

@verpeteren
Copy link
Contributor Author

normal build

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants