Zeitwerk ist ein effizienter und threadsicherer Code-Loader für Ruby. Solange das Projekt den Namenskonventionen folgt, kann Zeitwerk die richtigen Dateien finden und sie bei Bedarf oder im Voraus laden, ohne dass require oder require_dependency erforderlich sind. Zudem kann es laut diesem Artikel https://weblog.rubyonrails.org/2019/2/22/zeitwerk-integration-in-rails-6-beta-2/ eine kleine Leistungssteigerung für die Anwendung bieten.
Es gibt einige Schritte, die ich durchführen muss, um es zum Laufen zu bringen:
Den Namen einiger Klassen ändern, um der Rails-Namenskonvention zu entsprechen. Beispielsweise sollte die Datei canonical_url.rb die Klasse CanonicalUrl anstelle von CanonicalURL definieren. Ebenso sollte die Datei ondiff.rb die Klasse Onpdiff anstelle von ONPDiff definieren. Ein alternativer Ansatz wäre, einen benutzerdefinierten Inflector an das Projekt anzuhängen; ich denke jedoch, dass das Befolgen der Konvention eine bessere Wahl sein könnte – GitHub - fxn/zeitwerk: Efficient and thread-safe code loader for Ruby · GitHub
Ähnlich wie im vorherigen Punkt sollten benutzerdefinierte Validierungen, die sich im Verzeichnis validations befinden, gemäß der Konvention in ein Modul Validations gekapselt werden. Außerdem erben einige Validierungen von EachValidator und sollten ohne Namensraum zugänglich sein. Ich plane, sie in ein separates Verzeichnis zu verschieben und zu den Autoload-Pfaden hinzuzufügen.
Alle require_dependency-Anweisungen entfernen und sicherstellen, dass das Projekt funktioniert.
Alle require-Anweisungen entfernen und sicherstellen, dass Discourse funktioniert.
Sicherstellen, dass alle Plugins auf die erforderlichen Abhängigkeiten zugreifen können. Ich weiß noch nicht, wie ich dies erreichen kann. Ich möchte zunächst sicherstellen, dass Discourse ohne Plugins läuft.
Natürlich gibt es noch viele Unbekannte zu lösen. Ich werde Sie über den Fortschritt auf dem Laufenden halten. Wenn Sie jedoch Interesse haben, sich das anzusehen, habe ich hier angefangen, damit zu spielen: Commits · KrisKotlarek/discourse · GitHub
Bitte lassen Sie mich wissen, ob Sie bei der Implementierung von Zeitwerk Nachteile sehen oder ob Sie der Meinung sind, dass ich etwas übersehen habe.
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)