Zeitwerk is an efficient and thread-safe code loader for Ruby. As long as the project is following naming conventions, Zeitwerk can find correct files and load them on demand or upfront without the need for any require or require_dependency. Also, it may give a small performance boost to the application according to that article https://weblog.rubyonrails.org/2019/2/22/zeitwerk-integration-in-rails-6-beta-2/
There are a few steps I need to do to make it work
Change the name of few classes to follow Rails naming convention. For example file, canonical_url.rb should define CanonicalUrl class instead of CanonicalURL. Similarly file ondiff.rb should define Onpdiff class instead of ONPDiff. An alternative approach would be to hook custom inflector to the project, however, I think that following convention might be a better choice - GitHub - fxn/zeitwerk: Efficient and thread-safe code loader for Ruby · GitHub
Similar to the previous point, by convention custom validations living in validations directory should be wrapped with Validations module. Besides, some validations are inheriting from EachValidator and should be accessible without namespace. I am planning to move them to separate directory and add to autoload paths.
Remove all require_dependency and ensure that the project is working
Remove all require and ensure that Discourse is working
Ensure that all plugins can access the required dependencies. I don’t know how to achieve it yet. I want to firstly make Discourse running without any plugins.
Of course, there are still plenty of unknowns to solve. I will keep you updated about progress however if you are keen to look, I started playing with that here Commits · KrisKotlarek/discourse · GitHub
Please let me know if you see any drawbacks of implementing Zeitwerk or you think I missed something.
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 이제 진행해도 될 것 같습니다. 최신 master로 리베이스를 했고, Webauthn에 대한 작은 조정도 했습니다.
다음 3가지를 확인했습니다:
로컬에서 서버를 실행하고 조금씩 클릭하며 예상대로 작동하는지 확인
스펙 실행
모든 공식 플러그인을 다운로드하고 플러그인 스펙이 통과하는지 확인 (먼저 플러그인 조정을 병합해야 합니다)