Please create an account to participate in the Slashdot moderation system

 



Forgot your password?
typodupeerror
×
AI Python Programming

ChatGPT-Powered 'Scalene' Offers Efficiency Suggestions for Python Programmers (itbrew.com) 36

The tech site IT Brew looks at an open-source tool that "uses AI to offer efficiency-minded suggestions to Python coders." Known as "Scalene," the profiler — a kind of debugger for performance issues — has been downloaded more than 900,000 times on GitHub. "It's awesome in general, and amazing for an academic project," UMass professor Emery Berger, who worked with PhD students Sam Stern and Juan Altmayer Pizzorno on the open-source tool, told IT Brew...

Scalene measures how much time and memory is spent on each line of code — both on average and at peak, [and] how much time is spent in efficient libraries and how much is spent in Python... By selecting a lightning-bolt icon, a user can "leverage the engine that powers ChatGPT to get an optimization" suggestion, Berger said. In one demo he showed IT Brew, an output recommended a less-memory-intensive move to reduce a very large array created by the code...

"If your Python code already runs fast enough, then you don't need a profiler. But if it's running slow, I think it's a very convenient profiler to reach for," Berger said.

Link via Dev News .
This discussion has been archived. No new comments can be posted.

ChatGPT-Powered 'Scalene' Offers Efficiency Suggestions for Python Programmers

Comments Filter:
  • Given The (Score:5, Funny)

    by Barny ( 103770 ) on Sunday January 28, 2024 @05:59PM (#64195722) Journal

    Given the target audience, how much do you want to bet most of those downloads were from a bad Python script that kept fetching it over and over?

  • by devslash0 ( 4203435 ) on Sunday January 28, 2024 @06:34PM (#64195818)

    These kind of speed-ups come very naturally to professionals proficient with Python (such as myself). However, what matters more than speed is readability. Trying to teach students and novice programmers programming focusing on speed is bound to make them produce ugly, unreadable and unstructured code later on in their development life.

    import this:

    Beautiful is better than ugly.

    Explicit is better than implicit.

    Simple is better than complex.

    Complex is better than complicated.

    Flat is better than nested.

    Sparse is better than dense.

    Readability counts.

    Special cases aren't special enough to break the rules.

    Although practicality beats purity.

    Errors should never pass silently.

    Unless explicitly silenced.

    In the face of ambiguity, refuse the temptation to guess.

    There should be one-- and preferably only one --obvious way to do it.

    Although that way may not be obvious at first unless you're Dutch.

    Now is better than never.

    Although never is often better than *right* now.

    If the implementation is hard to explain, it's a bad idea.

    If the implementation is easy to explain, it may be a good idea.

    Namespaces are one honking great idea -- let's do more of those!

  • by gweihir ( 88907 ) on Sunday January 28, 2024 @06:35PM (#64195820)

    With a scripting language, you do not do detail optimization with a profiler. It is the wrong tool for the wrong job. You do algorithm optimization, you may look at execution times of larger tasks, but that is essentially it. If you want to optimize runtime then you move the critical parts to C and _there_ doing profiling makes sense. And on C-level, you can also optimize memory footprint, which is often very important for performance and even do cache-awareness. Forget doing that on Python level.

    And always remember, code optimization is for experienced experts only. If you are not one, you are far more likely to shoot yourself in the foot and may make your code unmaintainable or create even worse problems.

    • by ls671 ( 1122017 )

      Indeed, python is usually != efficiency and optimized code

    • by devslash0 ( 4203435 ) on Sunday January 28, 2024 @07:25PM (#64195952)

      Python is not a scripting language. It is a general-purpose interpreted language. Yes, it is frequently used as a scripting language but it's just a tiny part of its use cases.

      • by vivian ( 156520 ) on Sunday January 28, 2024 @07:45PM (#64195986)

        Python is a great language for knocking out code fast and flexibly, but if performance is a concern, it's the wrong tool for the job.
        I worked on a large ROS project that used python, C and C++ for various nodes to control a multi robot fab line. All the heavy lifting such as trajectory planning, evaluating laser scan data and updating world state was done in C++, with real-time controllers written in C, and a lot of task pipelining and messaging between various bits and pieces using Python. Occasionally when some new piece of equipment was being added to the system it might be controlled using a python script, but if it got to the point where that looked like it would be a bottleneck, it made a lot more sense to just rewrite or move some slow critical part out of the python script into a C++ node.

        • by gweihir ( 88907 )

          It depends. I did some high-performance stuff with Python (simulation). The way you do it is make a prototype in Python, then port the heavy lifting to C. This also allows for nice testing of the C code whether it delivers the same results as the Python code on test cases. In my real world application scenario, I brought the runtime down from about a month to about an hour for a run.

          Of course, you need to be firm enough in OO to understand how to do it in C, but it is really not that hard and the C interfac

        • Not all code needs to be maximally fast - just faster than it is at the moment.

          Sometimes performance problems are algorithmic and moving it to C++ will only marginally help. A profiler is there to help figure out where problems are. It is up to the programmer to study the output and figure out what needs changing. Sometimes minor code changes can lead to large speed improvements. The advice on moving it to C++ code is potentially advice to increase the complexity of the project - two languages, two build sy

      • by gweihir ( 88907 )

        Well, a scripting language is a type of "general purpose interpreted language". One typical characteristic is that you can use it interactively (check) and place the plain-text script in a text file with a "hash-bang" at the top (check). It is also not a systems-language which you can use, say, for compiled kernel modules or low-level manipulation or high-performance stuff (check on all three). And some more: https://en.wikipedia.org/wiki/... [wikipedia.org]

        So, yes, Python is a scripting language. It is also a general purp

    • by Draeven ( 166561 )

      Isn't that what the tool is proposing to do? It profiles your python code and finds opportunities (sections of code that run poorly) and makes suggestions for libraries or algorithms to improve it? In theory proposing libraries written in C, perhaps?

    • by narcc ( 412956 )

      In addition to algorithmic complexity, I'll add data structures. Though I'm not confident that developers these days would even know where to begin. There are other things that can be done to improve performance without introducing needless complexity. Simply reducing needless memory allocations and deallocations, for example, can dramatically improve performance.

      code optimization is for experienced experts only [...] make your code unmaintainable or create even worse problems.

      I get what you mean, but there's a lot of ground between 'picking better algorithms' and whatever Mel [utah.edu] gets up to these days.

      Optimization doesn

    • I am not sure why you (and many others) are so dismissive of this. Optimizations are often useful in any language where the program takes longer than a user would like (and the benefit or reprogramming is worth the effort). A profiler is just a tool to identify slow places in your code. Once you've identified the hotspot, you can then analyze its origin and figure out what to do about it. Maybe they're algorithmic (e.g. using an N^2 algorithm instead of N Log N), maybe they're just a poor implementation of

  • Use a real language.
  • by Canberra1 ( 3475749 ) on Sunday January 28, 2024 @08:16PM (#64196038)
    Where your boss reviewed all your code, and was an expert coder/programmer. Then occasionally we all got together in one room, a projector screen and discussed the code that passed reviews - and compile options and testing outcomes. Then management came along , sacked the testing team for finding too many defects, and the code review team for discovering poor programmers that only knew cut and paste - but were very quick at it. (Spaghetti prototype code) They had to be fired for upsetting DVI hires and slave B visa imports. Then sacked the usability testers, and the DBA's who looked for table scans etc. Better to do nothing and go for production testing.
    • ..when nobody would tell you that using bitwise and ("&") is "premature optimization" as it is "more complicated" than using remainder ("%")

      The reason you didnt hear it is because that boss would fire any fuck that got confused by bitwise operators .. if you are confused by bitwise operators, there is the door, leave... dont come back... we want programmers that know the basics, not ones that are confounded by the basics.
      • If you are arguing over whether to use bitwise operations you may be bikeshedding on questions that don't actually matter. Write code that is first correct, then maintainable, and only then maybe if you need to, worry about hand-optimizing.
        • Word salad.

          "Bikeshedding"

          The bloke declaring "premature optimization" and making a stink of it about & vs % .. they are the ones "bikeshedding"

          I cant help but notice that you picked a "side" and now you are claiming that the "other size" is guilty if what the "side" you picked did
          • I'm saying it usually isn't worth a debate. So long as the unit tests verify the code does the right thing, move on. Getting stuck on disagreements over implementation details shouldn't happen unless it's likely to affect readability or maintainability.
            • Unit Tests. What the F are those?! Programmers who write the code are expected to write their own unit tests, and are often ignorant of what or the range of values within the database. Classics are 'Court Orders' , Being Dead, with a lengthy contested probate, and companies shredding data/emails/evidence after seven years when the court case is still live. Married names, sex changes add to exceptions in the real world. Walkthrough's catch these exceptions. Hence the new phrase 'Production Testing' and 'no
    • Ah yes the "good old days". I remember having to try to figure out all that 70s junk code for Y2K. Thanks for making all the consultancy money necessary grandpa.

Children begin by loving their parents. After a time they judge them. Rarely, if ever, do they forgive them. - Oscar Wilde

Working...