question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

I have tested the simple code with Brython and Javascript:

<!doctype html>
<html>
    <head>
        <meta charset="utf-8">
        <script src="brython.js"></script>
        <script src="brython_modules.js"></script>
    </head>

    <body onload="brython(1)">
        <script type="text/python">
            from browser import console

            console.time('python')
            list = []
            i = 0
            while i < 100000:
                list.append(i)
                i += 1
            console.timeEnd('python')
        </script>
        <script>
            console.time('javascript')
            var list = [];
            for (var i = 0; i <= 100000; i++) {
                list.push(i);
            }
            console.timeEnd('javascript')
        </script>
        <div id="root"></div>
    </body>
</html>

And the results in Chrome are the following:

javascript: 2.59716796875ms
brython.js:5316 using indexedDB for stdlib modules cache
brython.js:9073 python: 289.85302734375ms

Profiling from Chrome is attached:

Profile-20200617T123405.zip

Also according the report Brython seems to be only 3 times slower … strange …

Seems like it should be investigated as time will be …

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:33 (33 by maintainers)

github_iconTop GitHub Comments

2reactions
PierreQuentelcommented, Jun 18, 2020

I have not accepted PR #1422 for reasons explained in detail in the comment, but using a cache to speed up attribute lookup is certainly a good idea !

The flexibility of arguments parsing in Brython (positional, keywords, defaults, positional-only, keyword-only, etc…) makes it hard to implement it efficiently in Javascript. By default, $B.args() is used, as it covers all the possible combinations.

In commit 0b154e018b7972f9f6d747d03dcc5b8f02994769 I have replaced it by a call to 2 functions for list.append()

    $B.check_no_kw("append", self, x)
    $B.check_nb_args("append", 2, arguments)

It makes the code above not far from 2 times faster than with $B.args(). The same optimization can be done for all methods that don’t support keyword arguments and expect exactly a given number of arguments, without default values.

1reaction
redradistcommented, Jun 19, 2020

@PierreQuentel

@redradist All I can say is, good luck ! Checking that a variable didn’t change just by looking at the code (static analysis) is terribly difficult because of the flexibility of the language. For instance:

* module **`mymodule.py`**
bla = globals
* module **`main.py`**
from mymodule import *

class A:

    @property
    def x(self):
        bla()["i"] = "z"

a = A()
i = 5
a.x
print(i + 1) # must fail, i is now "z"...

How would static analysis of main.py guess that the expression a.x changed the value of i ?

Initial Proof of Concept will be done at https://github.com/redradist/DOpter

Read more comments on GitHub >

github_iconTop Results From Across the Web

9 Examples of a Performance Issue - Simplicable Guide
A performance issue is a failure to meet the basic requirements of a job. They are based on reasonable expectations of behavior and...
Read more >
Dealing with Performance Problems
Types of Performance Problems ; Quantity of work (untimely completion, limited production). Poor prioritizing, timing, scheduling; Lost time ; Quality of work ( ......
Read more >
Handling Performance Issues With Grace | Monster.com
Low Productivity or Late Completion – Make sure you've been clear about the requirements and expectations of the job. · Poor Quality of...
Read more >
Top 5 Common Performance Problems - HRCI
Top 5 Common Performance Problems · Shallow Work · Inability to Prioritize · False Sense of Urgency · Productive Procrastination · Low-Quality Output....
Read more >
5 Common Reasons for Performance Issues (Plus 3 Tips to ...
Most Common Causes of Performance Issues · 1. They lack knowledge or skill. · 2. They have unclear or unrealistic expectations. · 3....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found