toga icon indicating copy to clipboard operation
toga copied to clipboard

implement Lazy Loading for Cocoa core imports

Open KRRT7 opened this issue 5 months ago • 5 comments

Fixes (partly) https://github.com/beeware/toga/issues/2547

PR Checklist:

  • [ x] All new features have been tested
  • [ x] All new features have been documented
  • [x ] I have read the CONTRIBUTING.md file
  • [x ] I will abide by the code of conduct

KRRT7 avatar Jul 01 '25 07:07 KRRT7

I'm not sure if you're aware of how to run the testbed on your own machine, but there are instructions here.

mhsmith avatar Jul 02 '25 20:07 mhsmith

Also - as @johnzhou721 has noted, the test_import that you've added won't ever be executed. That said - if the lazy import is done right, it won't need any additional tests - because the existing codebase is testing every valid import. All this change would do is modify how that import is implemented, making it (hopefully) faster.

Agreed. But I think we should have an explicict test about failed imports. Cocoa has now achieved 100% functionality coverage, so there's no Cocoa backend doesn't implement messages that come up, and we still need to verify that this functionality w/ doesn't impl messsages work correctly.

johnzhou721 avatar Jul 10 '25 01:07 johnzhou721

Agreed. But I think we should have an explicict test about failed imports. Cocoa has now achieved 100% functionality coverage, so there's no Cocoa backend doesn't implement messages that come up, and we still need to verify that this functionality w/ doesn't impl messsages work correctly.

Sure - but that's more of a "filling a testing gap that is currently hidden", rather than anything directly related to this PR. I've added #3632 to track this as an idea.

freakboy3742 avatar Jul 10 '25 01:07 freakboy3742

Wow... didn't realize it wasn't covered now!!! My eyes tend to ignore gray things (comments in Xcode as I don't even have a proper IDE just random apps that happens to open Python files), I guess.

johnzhou721 avatar Jul 10 '25 01:07 johnzhou721

if the lazy import is done right, it won't need any additional tests - because the existing codebase is testing every valid import. All this change would do is modify how that import is implemented, making it (hopefully) faster.

As we discussed in the toga-core lazy import PR, we should still have a test if possible, otherwise it would be easy to reintroduce an eager import by accident and not notice for years. The same approach can be used in this PR.

mhsmith avatar Jul 10 '25 13:07 mhsmith