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

[Question] Are any perfomance benefits by using the overload decorator inside native classes? #1039

Open
JotaRata opened this issue Nov 30, 2023 · 0 comments

Comments

@JotaRata
Copy link

JotaRata commented Nov 30, 2023

As the title says, are overloaded methods treated differently when compiled with mypyc?
Example:

class Example:
	
	@overload
	def method(self, count : int, type : Literal['float']) -> List[float]: ...
	@overload
	def method(self, count : int, type : Literal['int']) -> List[int]: ...

	def method(self, count : int, type : Literal['float', 'int']) -> List[float | int]:
		if type == 'float':
			return [3.14] * count
		elif type == 'int':
			return [3] * count
		else:
			raise ValueError(type)

In this example we create a list where the type of its content can change based on the input of the user, in this case the user can choose between 'float' and 'int'.

Imagining this is a more complex operation, does mypyc compile both functions using the different optimizations made for floats and integers that are explained in the documentaiton?

And if so, can overloading be used to optimize methods that may return multiple types?

If the result of this question is yes, then it should be included in the documentation along with other tips and tricks for optimization

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

1 participant