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

add some more (slightly of the codebase changed) speedups #1

Closed
wants to merge 2 commits into from

Conversation

owobred
Copy link
Owner

@owobred owobred commented Jun 7, 2023

(I'm using another device so these numbers aren't relative to the timings)

Current speedups

(ai-py3.11) PS C:\Users\bred\Documents\Programming\git\neuro-amongus> python .\AI\test.py
Parsing: recordings\1684614514.gymbag2
Updating game data
Update took 3.4974009001161903s
Saving: recordings\decoded\1684614514.pickle
Converting to neural network format...
Convert took 6.916246499866247s
Saving neural network format...

With a list of tuples instead of a dict

(ai-py3.11) PS C:\Users\bred\Documents\Programming\git\neuro-amongus> python .\AI\test.py
Parsing: recordings\1684614514.gymbag2
Updating game data
Update took 3.3351785000413656s
Saving: recordings\decoded\1684614514.pickle
Converting to neural network format...
Convert took 6.234746099915355s
Saving neural network format...

Re-using values in pad_list

(ai-py3.11) PS C:\Users\bred\Documents\Programming\git\neuro-amongus> python .\AI\test.py
Parsing: recordings\1684614514.gymbag2
Updating game data
Update took 3.3493349000345916s
Saving: recordings\decoded\1684614514.pickle
Converting to neural network format...
Convert took 3.315107800066471s
Saving neural network format...

@owobred owobred changed the title add some more (slightly of the codebase changed) speedus add some more (slightly of the codebase changed) speedups Jun 7, 2023
Comment on lines -55 to +56
to_concatenate = np.array([convert_type(padding_value()) if callable(padding_value) else convert_type(padding_value) for _ in range(len(lst), length)])
padding = convert_type(padding_value()) if callable(padding_value) else convert_type(padding_value)
to_concatenate = np.array([padding for _ in range(len(lst), length)])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This defeats the purpose of having padding_value be a callable. We don't want to reuse the same instance of the padding value, that's why we we pass in a callable as the argument. Unless something has changed since I wrote the code originally, reusing the same instance of that padding value might break some stuff.

Comment on lines -66 to +68
l = np.array([convert_type(padding_value()) if callable(padding_value) else convert_type(padding_value) for _ in range(length)])
padding = convert_type(padding_value()) if callable(padding_value) else convert_type(padding_value)
l = np.array([padding for _ in range(length)])

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here

@owobred owobred closed this Jun 7, 2023
Comment on lines +63 to +80
type_mapping: list[tuple[typing.Type, typing.Callable]] = [
(bool, convert_bool),
(dict, convert_dict),
(list, convert_list),
(str, convert_str),
(PositionData, convert_positiondata),
(TaskData, convert_taskdata),
(Vector2, convert_vector2),
(betterproto.Message, convert_message),
(betterproto.Enum, convert_enum),
(int, lambda x: [x]),
(float, lambda x: [x]),
(np.ndarray, lambda x: convert_list(x.tolist())),
]

#print(extra_info)

for cls, func in type_mapping.items():
for cls, func in type_mapping:

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is faster though you can include it in the other pr

@owobred
Copy link
Owner Author

owobred commented Jun 7, 2023

ty @Alexejhero, was unsure if these would have a negative effect in places given I didn't have much experience. The other speedup in this pr has very little benefit compared to this part.

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

Successfully merging this pull request may close these issues.

2 participants