Zeitwerk è un caricatore di codice efficiente e thread-safe per Ruby. Finché il progetto segue le convenzioni di denominazione, Zeitwerk può individuare i file corretti e caricarli su richiesta o in anticipo, senza la necessità di alcun require o require_dependency. Inoltre, secondo quell’articolo https://weblog.rubyonrails.org/2019/2/22/zeitwerk-integration-in-rails-6-beta-2/, potrebbe offrire un piccolo incremento delle prestazioni all’applicazione.
Ci sono alcune operazioni che devo eseguire per farlo funzionare:
Cambiare il nome di alcune classi per seguire la convenzione di denominazione di Rails. Ad esempio, il file canonical_url.rb dovrebbe definire la classe CanonicalUrl invece di CanonicalURL. Allo stesso modo, il file ondiff.rb dovrebbe definire la classe Onpdiff invece di ONPDiff. Un approccio alternativo sarebbe collegare un inflector personalizzato al progetto; tuttavia, penso che seguire la convenzione possa essere una scelta migliore - GitHub - fxn/zeitwerk: Efficient and thread-safe code loader for Ruby · GitHub
Analogamente al punto precedente, per convenzione le validazioni personalizzate presenti nella directory validations dovrebbero essere racchiuse nel modulo Validations. Inoltre, alcune validazioni ereditano da EachValidator e dovrebbero essere accessibili senza namespace. Intendo spostarle in una directory separata e aggiungerle ai percorsi di autoload.
Rimuovere tutti i require_dependency e assicurarsi che il progetto funzioni correttamente.
Rimuovere tutti i require e assicurarsi che Discourse funzioni correttamente.
Assicurarsi che tutti i plugin possano accedere alle dipendenze richieste. Non so ancora come realizzare ciò. Vorrei prima far funzionare Discourse senza alcun plugin.
Naturalmente, ci sono ancora molte incognite da risolvere. Terrò aggiornati sui progressi; tuttavia, se siete interessati a dare un’occhiata, ho iniziato a sperimentare qui: Commits · KrisKotlarek/discourse · GitHub
Fatemmi sapere se notate eventuali svantaggi nell’implementazione di Zeitwerk o se pensate che abbia tralasciato qualcosa.
I made some progress around Zeitwerk, however, I changed my approach. My original plan was to change every place where Discourse is not following the Zeitwerk filename convention. After a few fixes, I realised that this is just the tip of the iceberg and noticed that if I am going to follow that path, then pull request will be difficult to read and confidently merge to master. For example, all job classes under regular directory should have Regular namespace, same with Onceoff and Scheduled.
I decided to step back a little bit and think about a more evolutionary approach than revolutionary.
I decided that it would be better to introduce custom Inflector, which will cover all files which are not following Zeitwerk convention. The biggest benefit will be that we would be able to deploy that small change and once we are happy with Zeitwerk and we don’t have any performance downgrades, we can start fixing convention file by file in reasonable small pull requests.
I found some problems which could not be sorted by custom Inflector, so I made additional fixes to make it work.
Pull request is still in progress, however, at this stage, I can run Discourse with Zeitwerk and default plugins, run all specs and run benchmark without a problem.
I wanted first to be at that stable state when all specs are passing. Now I can confidently start removing all require_dependency one by one and also test official plugins. Once everything is ready, I will share with you benchmark results in this post.
We can try another way to benchmark. What would you say about more iterations, something which would run for an hour? In addition, instead of taking the best result, compare the average from each experiment. That may give more consistent numbers. What do you think?
@sam I think we are good to go, I rebased with the latest master and made a small adjustment to Webauthn.
I checked 3 things:
run the server on local and click a little bit to ensure it works as expected
run specs
downloaded all official plugins and ensured that specs for plugins are passing (we need to merge adjustments for plugins first)