Skip to content

Drastically Improve Variable Loading Speed - #8783

Open
erenkarakal wants to merge 8 commits into
SkriptLang:dev/patchfrom
erenkarakal:patch/faster-variable-loading
Open

Drastically Improve Variable Loading Speed#8783
erenkarakal wants to merge 8 commits into
SkriptLang:dev/patchfrom
erenkarakal:patch/faster-variable-loading

Conversation

@erenkarakal

@erenkarakal erenkarakal commented Jul 20, 2026

Copy link
Copy Markdown
Member

Disclaimer

To anyone looking to test this build. Make a backup of your variables file!

Problem

Skript's variable loading can be very slow as you get more variables. There are 3 main bottlenecks during variable loading.

  1. Regex is used to read the variables.csv file lines. It makes the code readable, but around 17% of the time is spent matching the line to the regex pattern.

  2. Inside DefaultYggdrasilInputStream, throw new EOFException() is used as a breakpoint. When this is called millions of times, it ends up taking up more than 20% of the tick.

  3. The variable name comparator in VariablesMap is taking 15% of the tick. I looked into it, but it's not addressed in this PR. I am not sure if it can be optimized.

Solution

1) Added a new FastEOFException exception. This exception overrides fillInStackTrace() to have an empty implementation, which makes variable loading around 30% faster. (33.8s -> 24.2s when loading 15 mil variables)

2) Rewrote the splitCSV method to not use regex, which is an additional 25%~ boost (24.2s -> 19.0s when loading 15 mil variables)

The rest of the changes are code cleanup, just IJ suggestions.

Testing Completed

The speed tests were done with a single list of 15 million global variables, each variable having a different number. This PR still needs heavy testing with different variable types and varying variable names to make sure no breaking changes were added.

This python script was used to generate the variables:

import csv

num_entries = 15_000_000
output_file = "variables.csv"

with open(output_file, "w", newline="") as f:
    writer = csv.writer(f)

    for i in range(num_entries):
        decimal = str(i)
        hex_value = f"{i:016X}"

        writer.writerow([
            f"a::{decimal}",
            "long",
            hex_value
        ])

print(f"Generated {num_entries:,} entries in {output_file}")

Completes: none
Related: none
AI assistance: Claude Sonnet 5 Medium was used in splitCSV rewrite

@erenkarakal
erenkarakal requested review from a team as code owners July 20, 2026 13:09
@erenkarakal
erenkarakal requested review from APickledWalrus and cheeezburga and removed request for a team July 20, 2026 13:09
@erenkarakal erenkarakal added enhancement Feature request, an issue about something that could be improved, or a PR improving something. needs testing Needs testing to determine current status or issue validity, or for WIP feature pulls. don't merge me !! For pull requests that should not be merged due to some outstanding dispute, conflict or dependency. labels Jul 20, 2026
@sovdeeth

Copy link
Copy Markdown
Member

As for the comparator, I've also looked into optimizing it, and it's pretty close to as good as it can be without changing behavior afaik. Not an easy source of performance at least.

@skriptlang-automation skriptlang-automation Bot added the needs reviews A PR that needs additional reviews label Jul 27, 2026

@sovdeeth sovdeeth left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would also like to see junit tests for the csv parser with a focus on edge cases

int start = pos;
while (pos < n && line.charAt(pos) != ',') {
if (line.charAt(pos) == '"')
return null; // quote in the middle of an unquoted value

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this might be allowed (quotes in things like var names?) Please double-check.


import java.io.EOFException;

public class FastEOFException extends EOFException {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

javadocs for why this exists would be good

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

don't merge me !! For pull requests that should not be merged due to some outstanding dispute, conflict or dependency. enhancement Feature request, an issue about something that could be improved, or a PR improving something. needs reviews A PR that needs additional reviews needs testing Needs testing to determine current status or issue validity, or for WIP feature pulls.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants