8000 Some optimizations ( type safe, avoid unnecessary memory manage, etc...). by Daylily-Zeleen · Pull Request #70 · TaloDev/godot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Some optimizations ( type safe, avoid unnecessary memory manage, etc...). #70

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

Closed

Conversation

Daylily-Zeleen
Copy link
Contributor
@Daylily-Zeleen Daylily-Zeleen commented Feb 24, 2025
  1. Use RefCounted to replace Node to avoid unnecessary memory manage for users.
  2. Use some new classes instead of tuple like Array.
  3. Let some APIs return result directly ( useful for async programming).
  4. Rename "object_name" and "display_name" to "name" (they are RefCounted and not conflict with Node.name now).
  5. Type safe.
  6. Some tiny fix.
  7. Create settings.cfg when plugin enableing instead of first time of running game.
  8. Remove "class_name XXXAPI" and rename "TimeUtils" to "TaloTimeUtils", ensure all exposed classes have "Talo" prefix to avoid contaminating users' namespaces.
  9. Add missing signals to ChannelsAPI: player_joined, player_left, channel_ownership_transferred, channels_deleted.

This is my first contribute to this repo. I'm not sure the changes in this pr is appropriate or not.
If this pr can be merged, the document should do some change, too.


Edit: Except for type safe and class_name changes, everything else have been separated into independent PR.

tudddorrr and others added 30 commits May 4, 2024 22:58
@Daylily-Zeleen Daylily-Zeleen force-pushed the daylily-zeleen/optimize branch from 9ce840e to d831939 Compare February 24, 2025 17:15
Copy link
Contributor
@tudddorrr tudddorrr left a comment

Choose a reason for hiding this comment

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

thank you for this massive PR! some really great changes in here and I've left comments about splitting these up into smaller PRs - that way its easier to test the functionality and we can revert commits if needed.

the places I haven't left comments are for 2 reasons:

  1. I agree with the non-controversial typing changes (i.e. places where there are no breaking changes). this could probably be its own PR where type safety is improved.
  2. I'd like to see some of the breaking changes in their own PR once all the other non-controversial changes have been pulled into their own PRs. If you could also point me to any documentation about performance improvements from RefCounted that would be great. The change from Node to RefCounted would cause a lot of breaking changes and it would be nice to have the confidence to say its worth it.

thanks again and please let me know if you have any questions

@@ -1,4 +1,5 @@
class_name ChannelsAPI extends TaloAPI
Copy link
Contributor

Choose a reason for hiding this comment

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

will use this file as a base for most of my comments:

  1. I'd like to keep using the class_name xAPI extends TaloAPI format - unless there's any reason not to. I like the declarative nature of showing exactly what the class name is.
  2. For consistency I'd prefer if we didn't use the p_ prefixes on variable names. I understand the idea behind it but I don't think the values are being shadowed in the same way they would be in other languages.
  3. Really love that you added these signals - would be great if the changes in this file could be pulled out into their own PR
  4. Similarly love the idea of the ChannelPage struct - if this could be part of the same PR as the above that would be great!

Copy link
Contributor Author
@Daylily-Zeleen Daylily-Zeleen Feb 25, 2025

Choose a reason for hiding this comment

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

  1. I think a plugin should avoid expose unnecessary class name, class_name is global scope, it will contaminate user's namespace. Any class_name in plugin should be thought twice.
    If you definitely want to keep them has an explicit class name, we can consider to user an independence script with a class_name and declare other scripts as a constant value like in "talo_manager.gd" in this pre.
    For example:
# talo.gd
class_name TaloScope # Maybe "TaloScope" is not an appropriate name of Talo namespace.

const ChannelsAPI = preload("apis/channels_api.gd")
...




# talo_manager.gd
...

var channels : TaloScope.ChannelsAPI
...

  1. This is mainly to improve maintainability, for example:
var name: String = "abc"

# The argument "name" is shadowing the property "name".
func foo(name: String) -> void:
    var a := name

    ...... # A very long piece of code.

    print(name) # Will print the value of argument "name". (Correct)

If we consider to change the argument "name" and fix relate logic partially, it will be like this:

var name: String = "abc"

# Change "name" to be an int value "id". 
func foo(id: int) -> void:
    var a := id

    ...... # A very long piece of code.

    # Because "name" is a property in this script, it will not be an error and easy to be ignored.
    print(name) # Will print "abc". (Wrong)

Copy link
Contributor

Choose a reason for hiding this comment

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

I fully see your point and agree in principle but I think the main problem with polluting namespaces is naming collisions. I'm hopeful that one day gdscript will add namespaces but until then I think 99.9% of Godot projects won't have any naming collisions with any of the Talo APIs

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can’t assume the user's naming preferences. For example, TimeUtils, it is entirely possible for the user to create type with the same name.
At least we need to add the prefix "Talo" to all Talo types like the C language library.

We can consider it from another perspective, reduce expose unnecessary types to users can reduce the number of related types in the completion list when users type "Talo" in code editor, so user can ignore them. This reduces unnecessary complexity and keep the simplicity of the API.
Especially for some types in the "utilis" folder, they are completely inaccessible to users but have a global class name, this is completely inappropriate.

Copy link
Contributor

Choose a reason for hiding this comment

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

yeah I think adding Talo as a prefix to the APIs is a good middle ground, especially because that won't lead to a breaking change

@Daylily-Zeleen
Copy link
Contributor Author
Daylily-Zeleen commented Feb 25, 2025

2. I'd like to see some of the breaking changes in their own PR once all the other non-controversial changes have been pulled into their own PRs. If you could also point me to any documentation about performance improvements from RefCounted that would be great. The change from Node to RefCounted would cause a lot of breaking changes and it would be nice to have the confidence to say its worth it.

Node can not freed automatically, it should be called queu_free() manually, or add as a child node and will be free with its parent node.
RefCounted is more lightweight and will be free automatically when it is no longer referenced.

You can refer this document for more details.

@Daylily-Zeleen
Copy link
Contributor Author

I will try to split this pr late.

@Daylily-Zeleen
Copy link
Contributor Author

An another naming issue:
According to my personal habits, I prefer to mark an asynchronous method explicitly by adding a suffix "_async".
By this way, I can know that I should use await to wait its return value without jumping to the method definition.

But this change quite huge, I'm not sure that it is worth or not. What do you think?

@tudddorrr
Copy link
Contributor

An another naming issue: According to my personal habits, I prefer to mark an asynchronous method explicitly by adding a suffix "_async". By this way, I can know that I should use await to wait its return value without jumping to the method definition.

But this change quite huge, I'm not sure that it is worth or not. What do you think?

I personally don't think so. The compiler throws an error if you miss an await with an async function: Function "make_request()" is a coroutine, so it must be called with "await".

@tudddorrr
Copy link
Contributor

Just wanted to say thank you very much for your hard work here - I really appreciate it. I've left some comments on the other PRs and will have a look at the remaining PRs tomorrow. Also very interested to read the multiplayer peer PR, would love to get an explanation from you about how your envision this feature working.

@Daylily-Zeleen
Copy link
Contributor Author

An another naming issue: According to my personal habits, I prefer to mark an asynchronous method explicitly by adding a suffix "_async". By this way, I can know that I should use await to wait its return value without jumping to the method definition.
But this change quite huge, I'm not sure that it is worth or not. What do you think?

I personally don't think so. The compiler throws an error if you miss an await with an async function: Function "make_request()" is a coroutine, so it must be called with "await".

I prefer to type a correct code without waiting compiler checking.

From another perspective, for example:

...
# Without "await", the compiler will not recognize this as error.
Talo.players.identify()
if Talo.identity_check() == OK:
    # Never be executed (Wrong)
    print(Talo.current_alias.id)

If we have a "_async" suffix, users can know that this is an asynchronous method form its name, user can avoid this issue to reduce time to debug or refer document.

Anyway, this just a suggestion.

@Daylily-Zeleen
Copy link
Contributor Author

Just wanted to say thank you very much for your hard work here - I really appreciate it. I've left some comments on the other PRs and will have a look at the remaining PRs tomorrow. Also very interested to read the multiplayer peer PR, would love to get an explanation from you about how your envision this feature working.

Please discuss in #85 .

@tudddorrr
Copy link
Contributor

Hey @Daylily-Zeleen I'm gonna close this PR since most of the changes are now merged via other PRs

@tudddorrr tudddorrr closed this Mar 20, 2025
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
0