[DRAFT] Optimisation (RW16.2+/RW17)
Optimisation for RW16.2 and higher
Not final, still planning this
Preface
RedWarn is not very fast at loading. In fact, it's often the last thing on the page to load - which doesn't bode well with our main aim of being fast
Algorithm rewrites
The following algorithms are to be rewritten either in JavaScript (will be made TypeScript for RW17) or C++
Warning Detection (C++)
Warning detection system is to be rewritten in C++ - the behaviour will be slightly different to current, showing 28 days of prior warnings instead of just this month header
Basic outline of new algorithm (C++):
Javascript 0. Get contents of last two page sections (i.e. this month and last so we can show definitively 28 days)
C++
- Find HTML comments in user page content
- Pick out template comments in a page (all UW templates have these) - we do this by checking if first 5 bytes are Templ
- Grab last number in that comment 3a. if number is 4 check if 4im (can just do this by checking if the length is X longer than the position of number) 3b. if no number found, respond with a policy violation or reminder note
- Check if higher than last warning level detected
- Find closest signature to attribute a date and author, ensure date is in the last 28 days (repeat until all instances checked)
- Return 4 values, warning level, warning author, warning date and time, warning template
Then additional checking stage (JavaScript): After RW has provided at least some input to automation and user, a more in depth, done async
- detect blocks
- identify exact warnings/reminders if applicable
- identify recently removed warnings (go back only 5 revisions for automation)
Parsing Wikitext (lang TBC, either PHP or C++)
Parsing Wikitext is slow as we have to go client > server > client (loading images) > server - especially when things like the warn dialog won't let you through until it is parsed
Ideally we can do this client-size nearly instantly for basic tasks. Local cache of commonly used templates (inc all warning templates), and ones that aren't found can then be loaded remotely
Adding section to userpage
Whitespace issues etc. on current
The algorithm will do 3 things:
- Fix duplicate date headers, if present
- Create a new header or use the existing one, add the template
- Return that wikitext
Basic summary: If not adding date, see step x
- Check if there are two current month headers, find signatures and identify date. Remove the newest one, and transfer content into above headers
- Place warning into existing header. If header doesn't exist, create it. If adding to the bottom of a page, add newlines, else omit them
- Return the wikitext
Context
Q&A
Why nonTS support?
- Establish a working framework early during RW17 development
- Better UX
Why C++?
- Highly flexible, allows other projects to use our algorithms offline and online
- Fast wasm compilation
- Fairly low level
- I know my way around it