Python performance usage Problems

Source: Internet
Author: User

In Python: code written and tested using Python performance, and then the important part is converted to CPython to improve its speed, which greatly reflects the Python performance, the following is a detailed analysis.

Recently, it is rumored that Google will restrict the use of Python in its new project. For this reason, some developers (expressed in K) publicly asked Collin Winter in the Google forum, collin Winter answered many acute questions. This post also attracts many high-quality posts. K: I have heard that Google will restrict the use of Python in its new project, which will undoubtedly greatly reduce the support for Python code and Python. Is it true that it is a rumor?

Collin Winter: indeed, Google will restrict Python applications because Python is not as fast as Java and C ++, thread occupation, and memory usage are high when Python is used to develop a new system. We know what the system will do if the load is increased by 10 times or 100 times, and how bad the developed service will be. I think Python has developed into a slit.

Therefore, we should weigh the advantages and disadvantages of the choice. Maybe developers can use Python very efficiently, but as the system grows, there will be many platform-level performance restrictions. K: Will Unladen Swallow change all of this? What are your expectations? Collin Winter: Unladen Swallow is designed to use Python in as many places as possible that it is not currently involved.

Moreover, Unladen Swallow is not a panacea for all diseases. If no one has invested in Python, Python will still be slower than C and Java, occupying more memory and threads. I hope that the developer's attention to Python will form a virtuous circle: the more developers are interested and the more companies are interested, the more investment is injected, to develop more Python resources.

I think the best thing about Python and other dynamic languages is that many developers work on different subsystems, but they all work on the same code base. The C or C ++ languages are different. The more developers participate, the more fragmented the code base. From this perspective, dynamic languages are easier to operate in sandbox. This agility and flexibility are important features of the Python language.

K: Python is indeed slower than C and Java, But it compares v8 JavaScript Engine, will it be the competitor of the latter? Collin Winter: I don't think apps like CPython can be as fast as V8 or SquirrelFish Extreme.

After all, the latter two are designed for speed. We have also encountered some high-speed performance optimizations, but it is difficult to configure them in CPython, so we can only give up. As a volunteer for open-source projects, CPython and V8 have different focuses: CPython emphasizes simplicity.

That is, the simple and slightly slow kernel is easy for people to maintain in their spare time. I have a high expectation for another Python project, PyPy, and hope it can get rid of the limitations of C-level backward compatibility and provide long-term performance solutions. But this wish may take ten years.

K: Why does CPython consider people's maintenance in their spare time? Collin Winter: CPython developers are rarely paid, and almost all of them are volunteers, while Ruby developers can obtain funds from sponsors such as EngineYard. So when they realize that the MRI servo web application is slow, they can better develop their VMS. This also determines that the things we develop take care of the needs of most people.

A Leon Sit developer adds here: I think CPython is not doing well in the aspect of digital code when the system grows. CPython depends on the C editor, but Windows does not have the C editor.

To speed up Python performance, print information needs to be added, and the syntax involved is not the standard syntax of Python. K: What about Jython? Another major goal of Collin Winter. Unladen Swallow is to maintain compatibility with the C extension module. The latter is widely used by Google. Using Jython requires porting the infrastructure from SWIG to JNI, which is a very painful task and will inevitably bring about very tedious bugs.

This is the primary reason why Jython is not selected as the baseline. Jython is a full-time paid developer. So far, IronPython and Jython have to focus most of their development efforts on compatibility with CPython. There is little focus on performance optimization. It can also be seen that supporting Python 3 affects projects such as Jython, IronPython, and PyPy. Tom Machinski believes that CPython is not compatible with low-level virtual machines (LLVM.

Do not get me wrong. Of course I am very interested in the Unladen Swallow project and hope it can truly achieve the goal. But I absolutely agree with Collin: even if all the goals of the Unladen Swallow project can be truly achieved, Python is not a competitor of Java or C ++.

Some developers asked: why companies like Google do not need to write a prototype in Python, and then gradually convert the core part into Cyhton, so that they can take advantage of Python, can the efficiency and performance of C be optimized? Craig Citro replied: I think this is a new plan for Google to develop Python.

Write code with Python performance, perform tests, and then convert important parts into CPython to improve the speed. However, this is undoubtedly a huge task, and what Collin Winter mentioned above is just to increase the speed of Python running and keep Python in Google.

At present, CPython and Unladen Swallow have many contradictions. For example, Unladen Swallow wants to introduce many runtime optimizations and features, but CPython cannot. But just as HotSpot JVM can beat g ++ in some standard aspects.

It is not difficult for CPython to beat simple Python code static editing. For example, if you want to write a special application and you care about performance, CPython is a great choice. You can convert an object to a local C data type. If you convert the Python code to CPython for a hassle, the JIT editor will optimize the pure Python code.

Note: Unladen Swallow is a branch of Python and is composed of a group of developers from Google. Google uses Python in many application projects, such as internal server monitoring and external Google Groups.

Therefore, Google naturally hopes to improve Python performance. This project is designed to improve Python execution efficiency. The goal of Unladen Swallow is to increase Python performance by five times. To achieve this goal, JIT support will be added and virtual machines will be re-designed. While improving performance, CPython ensures source code compatibility.

Unladen Swallow project leaders and core developers include: Collin Winter, Jeffrey Yasskin, and Thomas Wouters. They are all core developers who have been engaged in CPython for a long time. They contributed 20% of their free working hours to Unladen Swallow. But the Organization insisted that this was a Python project, not Google.

  1. Introduction to Python system files
  2. How to correctly use Python Functions
  3. Detailed introduction and analysis of Python build tools
  4. Advantages of Python in PythonAndroid
  5. How to Use the Python module to parse the configuration file?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.