How to turn a python extension into a C++ one?

I want to speedup the extension, and I wonder if this is a feasible way. and how to do it.

It depends on which extension you are looking at, and what it does. Many extensions just invoke ITK algorithms and/or VTK visualizations, and then there’s little to gain from a compiled extension. Others do relatively simple mathematical operations on volumes, and are sometimes written to do this by looping on arrays in Python – and then can be sped up by orders of magnitude by using numpy array operations instead, while staying in Python.

To turn a Python extension into a C++ one, you essentially need to rewrite it. This also requires building your extension, which may not be trivial (depending on your familiarity with creating C++ extensions for Slicer).

To summarize: It can be done, but – unless you are doing something extremely special – I would recommend looking at other options first.