Now you can use YAML!

  • Welcome to skUnity!

    Welcome to skUnity! This is a forum where members of the Skript community can communicate and interact. Skript Resource Creators can post their Resources for all to see and use.

    If you haven't done so already, feel free to join our official Discord server to expand your level of interaction with the comminuty!

    Now, what are you waiting for? Join the community now!

  • LOOKING FOR A VERSION OF SKRIPT?

    You can always check out skUnity Downloads for downloads and any other information about Skript!

Status
Not open for further replies.

Pikachu

Supporter
Addon Developer
Jan 25, 2017
870
144
43
USA
THE FOLLOWING ONLY APPLIES WHEN USING "skript-yaml" FOR YAML

Why use YAML?

Rezz said:
Skript’s goal is to give absolutely anyone, regardless of prior programming knowledge, the ability to modify and customize their server. In fact, Skript’s level of entry is so low many people inevitably find themselves picking it up as their first programming language (whether or not that’s a good thing is a debate for another day). Those who eventually become comfortable with their scripting abilities then try to emulate regular Java plugins as much as possible, and this is where YAML comes to mind.

YAML is the configuration file format officially supported by Bukkit (and its forks, like Spigot), which makes YAML an obvious choice for plugins wanting easy-to-implement and easy-to-manage configs; a majority of plugins use ‘config.yml’ as their sole means of customization. So any script author who wants to create an accurate plugin illusion would use ‘config.yml’ too, right?

What was wrong with YAML?

Rezz said:
The problem with YAML in Skript is that every addon that supports it parses YAML files every single time their syntax is used. In other words, whenever you retrieve a single value from a YAML file, ALL bytes are read, ALL values are parsed, and EVERYTHING but the specific value you were looking for is immediately thrown away. This is the exact opposite of how YAML is used by actual plugins; YAML files aren’t parsed over and over again, they’re parsed once and stored in memory -- much like Skript’s own variables.
[...]
All three addons behave in the same way: parse the entire file, get the value, and discard everything. Again, this is the exact, polar opposite of normal plugin behavior. It’s also terrible for performance; reading a file from disk isn’t a light operation, but then also parsing its contents every single time is icing on the cake. Using YAML in any of your scripts (in its current state, at least) is a guaranteed performance cut.

How much better is it now?

Using skript-yaml results in an insane increase in performance compared to skUtilities, skQuery and Skellett.
  • Before (without skript-yaml):
    DXjfq3Z.png

  • After (with skript-yaml):
    upload_2017-11-11_0-37-3.png
code_language.skript:
Setting 2500 variables...
Set 250 variables. 0.26 seconds since starting.
Set 500 variables. 0.47 seconds since starting.
Set 750 variables. 0.69 seconds since starting.
Set 1000 variables. 0.9 seconds since starting.
Set 1250 variables. 1.24 seconds since starting.
Set 1500 variables. 1.46 seconds since starting.
Set 1750 variables. 1.62 seconds since starting.
Set 2000 variables. 1.77 seconds since starting.
Set 2250 variables. 1.91 seconds since starting.
Set 2500 variables. 2.06 seconds since starting.
Variable-set test: 2.06 seconds
Setting 2500 YAML values...
Set 250 YAML values. 0.01 seconds since starting.
Set 500 YAML values. 0.02 seconds since starting.
Set 750 YAML values. 0.02 seconds since starting.
Set 1000 YAML values. 0.04 seconds since starting.
Set 1250 YAML values. 0.04 seconds since starting.
Set 1500 YAML values. 0.05 seconds since starting.
Set 1750 YAML values. 0.06 seconds since starting.
Set 2000 YAML values. 0.06 seconds since starting.
Set 2250 YAML values. 0.06 seconds since starting.
Set 2500 YAML values. 0.07 seconds since starting.
YAML-set test: 0.17 seconds
Testing 2500 random variables
Got 250 values. 0.33 seconds since starting.
Got 500 values. 0.59 seconds since starting.
Got 750 values. 0.75 seconds since starting.
Got 1000 values. 0.96 seconds since starting.
Got 1250 values. 1.12 seconds since starting.
Got 1500 values. 1.28 seconds since starting.
Got 1750 values. 1.43 seconds since starting.
Got 2000 values. 1.6 seconds since starting.
Got 2250 values. 1.73 seconds since starting.
Got 2500 values. 1.91 seconds since starting.
Variable-get test: 1.91 seconds
Testing 2500 random YAML values
Got 250 YAML values. 0.15 seconds since starting.
Got 500 YAML values. 0.28 seconds since starting.
Got 750 YAML values. 0.41 seconds since starting.
Got 1000 YAML values. 0.57 seconds since starting.
Got 1250 YAML values. 0.71 seconds since starting.
Got 1500 YAML values. 0.85 seconds since starting.
Got 1750 YAML values. 0.98 seconds since starting.
Got 2000 YAML values. 1.14 seconds since starting.
Got 2250 YAML values. 1.27 seconds since starting.
Got 2500 YAML values. 1.4 seconds since starting.
YAML-get test: 1.4 seconds
-- RESULTS: ---
Set 2500 variables test: 2.06 seconds
Set 2500 YAML values test: 0.17 seconds
Get 2500 variables test: 1.91 seconds
Get 2500 YAML values test: 1.4 seconds

Should I go changing everything to YAML?

No, absolutely not. Variables are still the preferred way of storing data within Skript. That said, skript-yaml does make YAML a hell of a lot more viable and flexible for more than just config files.

Where can I get skript-yaml?

You can find skript-yaml here.

What did you use to test this?
I made an edit of Rezz's yaml test.
code_language.skript:
options:

    PAUSE: wait 2 ticks
 
    SET_TESTS: 2500
    SET_PAUSE: 250
 
    GET_TESTS: 2500
    GET_PAUSE: 250
 
on script load:
 
    delete {test::*}
 
on script unload:
 
    delete {test::*}
 
function randomString(length: integer = 20, alphabet: string = "abcdefghijklmnopqrstuvwxyz0123456789-_") :: string:
 
    set {_chars::*} to {_alphabet} split at ""
    set {_string} to ""
 
    while length of {_string} is less than {_length}:
 
        set {_string} to "%{_string}%%random element out of {_chars::*}%"
   
    return {_string}
 
command /test:
    trigger:
 
        delete {test::*}
   
        broadcast "&aSetting {@SET_TESTS} variables..."
   
        set {_var-set-start} to now
        set {_var-set-iterations} to 0
   
        while {_var-set-iterations} is less than {@SET_TESTS}:
   
            set {_key} to randomString()
       
            {test::%{_key}%} isn't set
       
            set {test::%{_key}%} to {_key}
       
            add 1 to {_var-set-iterations}
       
            mod({_var-set-iterations}, {@SET_PAUSE}) is 0
       
           
       
            broadcast "Set %{_var-set-iterations}% variables. %difference between now and {_var-set-start}% since starting."
       
        set {_var-set-time} to difference between now and {_var-set-start}
        broadcast "&6Variable-set test:&f %{_var-set-time}%"
       
        if file "plugins/test/test.yml" exists:
            delete file "plugins/test/test.yml"
        load yml "plugins/test/test.yml"

        broadcast "&aSetting {@SET_TESTS} YAML values..."
       
        set {_yaml-set-start} to now
        set {_yaml-set-iterations} to 0
   
        loop {test::*}:
   
            set skript-yaml value loop-index in "test" to loop-value
            add 1 to {_yaml-set-iterations}
       
            mod({_yaml-set-iterations}, {@SET_PAUSE}) is 0
       
           
       
            broadcast "Set %{_yaml-set-iterations}% YAML values. %difference between now and {_yaml-set-start}% since starting."
        save yml "test"
        set {_yaml-set-time} to difference between now and {_yaml-set-start}
        broadcast "&6YAML-set test: &f%{_yaml-set-time}%"
   
        #
        #   GET TESTS
        #
        broadcast "&aTesting {@GET_TESTS} random variables"
   
        set {_var-get-start} to now
   
        loop {@GET_TESTS} times:
   
            set {_var-get-key} to a random element out of {test::*}
            set {_var-get-value} to {test::%{_var-get-key}%}
       
            mod(loop-number, {@GET_PAUSE}) is 0
       
           
   
            broadcast "Got %loop-number% values. %difference between now and {_var-get-start}% since starting."
   
        set {_var-get-time} to difference between now and {_var-get-start}
        broadcast "&6Variable-get test: &f%{_var-get-time}%"
   
        broadcast "&aTesting {@GET_TESTS} random YAML values"
   
        set {_yaml-get-start} to now
   
        loop {@GET_TESTS} times:
   
            set {_yaml-get-key} to a random element out of {test::*}
            set {_yaml-get-value} to skript-yaml value {_yaml-get-key} from "test"
            mod(loop-number, {@GET_PAUSE}) is 0
       
           
   
            broadcast "Got %loop-number% YAML values. %difference between now and {_yaml-get-start}% since starting."
           
        set {_yaml-get-time} to difference between now and {_yaml-get-start}
        broadcast "&6YAML-get test: &f%{_yaml-get-time}%"
   
        broadcast "<light red>-- RESULTS: ---"
        broadcast "&bSet {@SET_TESTS} variables test:&f %{_var-set-time}%"
        broadcast "<yellow>Set {@SET_TESTS} YAML values test: &f%{_yaml-set-time}%"
        broadcast "&bGet {@GET_TESTS} variables test: &f%{_var-get-time}%"
        broadcast "<yellow>Get {@GET_TESTS} YAML values test: &f%{_yaml-get-time}%"
 
THE FOLLOWING ONLY APPLIES WHEN USING "skript-yaml" FOR YAML

Why use YAML?



What was wrong with YAML?



How much better is it now?

Using skript-yaml results in an insane increase in performance compared to skUtilities, skQuery and Skellett.
code_language.skript:
Setting 2500 variables...
Set 250 variables. 0.26 seconds since starting.
Set 500 variables. 0.47 seconds since starting.
Set 750 variables. 0.69 seconds since starting.
Set 1000 variables. 0.9 seconds since starting.
Set 1250 variables. 1.24 seconds since starting.
Set 1500 variables. 1.46 seconds since starting.
Set 1750 variables. 1.62 seconds since starting.
Set 2000 variables. 1.77 seconds since starting.
Set 2250 variables. 1.91 seconds since starting.
Set 2500 variables. 2.06 seconds since starting.
Variable-set test: 2.06 seconds
Setting 2500 YAML values...
Set 250 YAML values. 0.01 seconds since starting.
Set 500 YAML values. 0.02 seconds since starting.
Set 750 YAML values. 0.02 seconds since starting.
Set 1000 YAML values. 0.04 seconds since starting.
Set 1250 YAML values. 0.04 seconds since starting.
Set 1500 YAML values. 0.05 seconds since starting.
Set 1750 YAML values. 0.06 seconds since starting.
Set 2000 YAML values. 0.06 seconds since starting.
Set 2250 YAML values. 0.06 seconds since starting.
Set 2500 YAML values. 0.07 seconds since starting.
YAML-set test: 0.17 seconds
Testing 2500 random variables
Got 250 values. 0.33 seconds since starting.
Got 500 values. 0.59 seconds since starting.
Got 750 values. 0.75 seconds since starting.
Got 1000 values. 0.96 seconds since starting.
Got 1250 values. 1.12 seconds since starting.
Got 1500 values. 1.28 seconds since starting.
Got 1750 values. 1.43 seconds since starting.
Got 2000 values. 1.6 seconds since starting.
Got 2250 values. 1.73 seconds since starting.
Got 2500 values. 1.91 seconds since starting.
Variable-get test: 1.91 seconds
Testing 2500 random YAML values
Got 250 YAML values. 0.15 seconds since starting.
Got 500 YAML values. 0.28 seconds since starting.
Got 750 YAML values. 0.41 seconds since starting.
Got 1000 YAML values. 0.57 seconds since starting.
Got 1250 YAML values. 0.71 seconds since starting.
Got 1500 YAML values. 0.85 seconds since starting.
Got 1750 YAML values. 0.98 seconds since starting.
Got 2000 YAML values. 1.14 seconds since starting.
Got 2250 YAML values. 1.27 seconds since starting.
Got 2500 YAML values. 1.4 seconds since starting.
YAML-get test: 1.4 seconds
-- RESULTS: ---
Set 2500 variables test: 2.06 seconds
Set 2500 YAML values test: 0.17 seconds
Get 2500 variables test: 1.91 seconds
Get 2500 YAML values test: 1.4 seconds

Should I go changing everything to YAML?

No, absolutely not. Variables are still the preferred way of storing data within Skript. That said, skript-yaml does make YAML a hell of a lot more viable and flexible for more than just config files.

Where can I get skript-yaml?

You can find skript-yaml here.

What did you use to test this?
I made an edit of Rezz's yaml test.
code_language.skript:
options:

    PAUSE: wait 2 ticks

    SET_TESTS: 2500
    SET_PAUSE: 250

    GET_TESTS: 2500
    GET_PAUSE: 250

on script load:

    delete {test::*}

on script unload:

    delete {test::*}

function randomString(length: integer = 20, alphabet: string = "abcdefghijklmnopqrstuvwxyz0123456789-_") :: string:

    set {_chars::*} to {_alphabet} split at ""
    set {_string} to ""

    while length of {_string} is less than {_length}:

        set {_string} to "%{_string}%%random element out of {_chars::*}%"
 
    return {_string}

command /test:
    trigger:

        delete {test::*}
 
        broadcast "&aSetting {@SET_TESTS} variables..."
 
        set {_var-set-start} to now
        set {_var-set-iterations} to 0
 
        while {_var-set-iterations} is less than {@SET_TESTS}:
 
            set {_key} to randomString()
      
            {test::%{_key}%} isn't set
      
            set {test::%{_key}%} to {_key}
      
            add 1 to {_var-set-iterations}
      
            mod({_var-set-iterations}, {@SET_PAUSE}) is 0
      
          
      
            broadcast "Set %{_var-set-iterations}% variables. %difference between now and {_var-set-start}% since starting."
      
        set {_var-set-time} to difference between now and {_var-set-start}
        broadcast "&6Variable-set test:&f %{_var-set-time}%"
      
        if file "plugins/test/test.yml" exists:
            delete file "plugins/test/test.yml"
        load yml "plugins/test/test.yml"

        broadcast "&aSetting {@SET_TESTS} YAML values..."
      
        set {_yaml-set-start} to now
        set {_yaml-set-iterations} to 0
 
        loop {test::*}:
 
            set skript-yaml value loop-index in "test" to loop-value
            add 1 to {_yaml-set-iterations}
      
            mod({_yaml-set-iterations}, {@SET_PAUSE}) is 0
      
          
      
            broadcast "Set %{_yaml-set-iterations}% YAML values. %difference between now and {_yaml-set-start}% since starting."
        save yml "test"
        set {_yaml-set-time} to difference between now and {_yaml-set-start}
        broadcast "&6YAML-set test: &f%{_yaml-set-time}%"
 
        #
        #   GET TESTS
        #
        broadcast "&aTesting {@GET_TESTS} random variables"
 
        set {_var-get-start} to now
 
        loop {@GET_TESTS} times:
 
            set {_var-get-key} to a random element out of {test::*}
            set {_var-get-value} to {test::%{_var-get-key}%}
      
            mod(loop-number, {@GET_PAUSE}) is 0
      
          
 
            broadcast "Got %loop-number% values. %difference between now and {_var-get-start}% since starting."
 
        set {_var-get-time} to difference between now and {_var-get-start}
        broadcast "&6Variable-get test: &f%{_var-get-time}%"
 
        broadcast "&aTesting {@GET_TESTS} random YAML values"
 
        set {_yaml-get-start} to now
 
        loop {@GET_TESTS} times:
 
            set {_yaml-get-key} to a random element out of {test::*}
            set {_yaml-get-value} to skript-yaml value {_yaml-get-key} from "test"
            mod(loop-number, {@GET_PAUSE}) is 0
      
          
 
            broadcast "Got %loop-number% YAML values. %difference between now and {_yaml-get-start}% since starting."
          
        set {_yaml-get-time} to difference between now and {_yaml-get-start}
        broadcast "&6YAML-get test: &f%{_yaml-get-time}%"
 
        broadcast "<light red>-- RESULTS: ---"
        broadcast "&bSet {@SET_TESTS} variables test:&f %{_var-set-time}%"
        broadcast "<yellow>Set {@SET_TESTS} YAML values test: &f%{_yaml-set-time}%"
        broadcast "&bGet {@GET_TESTS} variables test: &f%{_var-get-time}%"
        broadcast "<yellow>Get {@GET_TESTS} YAML values test: &f%{_yaml-get-time}%"

thanks you!
p.s. it does not seem on spaghetti code but many this waited
 
Nice project, but I think it's important to note that using add %objects% to {var::*} also has some serious performance problems.

Adding 2500 variables to a 10000 variable list:
Code:
[23:54:57 INFO]: [Skript] # /testvar
[23:55:08 INFO]: [Skript] # testvar took 11021.532949 milliseconds

It seems to parse everything everytime you add something to that list, causing a huge performance loss.

Using random numbers to set variables:
Code:
command /testvar:
   trigger:
       loop 2500 times:
           set {list::%a random integer between 100000000 and 99999999%} to "ABC"
Code:
[23:54:03 INFO]: [Skript] # /testvar
[23:54:03 INFO]: [Skript] # testvar took 15.564432 milliseconds

From 11 seconds to 0.015 seconds.
I think that some part of your code is making the variable test set be slower, even though you don't use "add", as it seems to be pretty fast here.
 
Nice project, but I think it's important to note that using add %objects% to {var::*} also has some serious performance problems.

Adding 2500 variables to a 10000 variable list:
Code:
[23:54:57 INFO]: [Skript] # /testvar
[23:55:08 INFO]: [Skript] # testvar took 11021.532949 milliseconds

It seems to parse everything everytime you add something to that list, causing a huge performance loss.

Using random numbers to set variables:
Code:
command /testvar:
   trigger:
       loop 2500 times:
           set {list::%a random integer between 100000000 and 99999999%} to "ABC"
Code:
[23:54:03 INFO]: [Skript] # /testvar
[23:54:03 INFO]: [Skript] # testvar took 15.564432 milliseconds

From 11 seconds to 0.015 seconds.
I think that some part of your code is making the variable test set be slower, even though you don't use "add", as it seems to be pretty fast here.
Good point, but i don't think its not a big deal because like I said in the post variables should still be used. The main point is still true regardless -- YAML is a fuckton faster than it was and its actually viable now.
 
Status
Not open for further replies.