Skip to main content

News

Topic: miniSphere 5.3b2 (stable: 5.2.13) (Read 340449 times) previous topic - next topic

0 Members and 4 Guests are viewing this topic.
  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: miniSphere 5.2.12
Reply #2220
Okay, so I know I said that 5.2.11 would be the last 5.2 release, but the bug fixes were starting to pile up so I decided to put out another patch.  Besides bug fixes I also added an explanation of API levels to the documentation as well as showing which level each function requires.  Experimental functions are marked as such.
miniSphere 5.3-beta1 (stable: 5.2.13) - Cell compiler - SSj debugger
forum thread | on GitHub

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: miniSphere 5.3 beta 1 (stable: 5.2.13)
Reply #2221
The first beta of miniSphere 5.3 is out, bringing some new APIs and several useful features, including cell init for initializing a new, working project directly from the command-line (no Sphere Studio required!).  More will be coming, but this seemed like a good point to push out a beta to hopefully get some field testing in on the new features, especially cell init.
miniSphere 5.3-beta1 (stable: 5.2.13) - Cell compiler - SSj debugger
forum thread | on GitHub

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: miniSphere 5.3b1 (stable: 5.2.13)
Reply #2222
Starting in miniSphere 5.3, from() will be built into the Core API without the need to import the "from" module.  Like @Radnen 's Link.js library that came before it, from() queries are often incredibly useful in battle engines, and now I've written some code in the engine to compile these queries directly to JS for super-fast performance.

Code: (JavaScript) [Select]
let dinnerAmount = from(worldPopulation)
    .where(it => pig.isHungryFor(it))
    .besides(it => pig.devour(it))
    .reduce((a, it) => a + it.weight, 0);
SSj.log(`the pig just gained ${dinnerAmount} lbs.`);
  • Last Edit: November 17, 2018, 03:24:15 pm by Fat Cerberus
miniSphere 5.3-beta1 (stable: 5.2.13) - Cell compiler - SSj debugger
forum thread | on GitHub

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: miniSphere 5.3b1 (stable: 5.2.13)
Reply #2223
So when I said above that from queries would be blazing fast, I meant it, and to prove it I've done a quick benchmark of other similar solutions:
Code: (javascript) [Select]
let fromQuery = new Query()
.where(it => it % 2 === 0)
.take(10000)
.select(it => it + 1)
.reduce((a, it) => a + it, 0);
Code: [Select]
 event                    count   time (us)   % run  avg (us)    % avg |
------------------------------------------------------------------------
 Array method chain       1,001   3,605,798  34.1 %     3,602   34.3 % |
 Underscore chain         1,001   2,065,016  19.5 %     2,062   19.6 % |
 Lodash chain             1,001   1,168,390  11.0 %     1,167   11.1 % |
 from.js 1.0              1,001     903,805   8.5 %       902    8.6 % |
 from.ts (Oozaru)         1,001     875,786   8.3 %       874    8.3 % |
 Link.js query            1,001     475,447   4.5 %       474    4.5 % |
 Link.js query (NR)       1,001     325,084   3.1 %       324    3.1 % |
 from.js 2.0              1,001     319,423   3.0 %       319    3.0 % |
 Lazy.js sequence         1,001     270,130   2.6 %       269    2.6 % |
 Sphere from() query      1,001     205,757   1.9 %       205    2.0 % |
 Sphere Query object      1,001     188,966   1.8 %       188    1.8 % |
 handwritten 'for' loop   1,001     119,092   1.1 %       118    1.1 % |

Sphere from() query and Sphere Query object is us!  All timings are for running a chain equivalent to the above query 1,000 times with the respective library over an array of 100,000 random integers between 0 and 1000.

Special thanks to @Radnen for (indirectly) giving me the idea - Link.js was touted as a replacement for writing repetitive for loops, which got me to thinking... what if I just compile the query to an actual for loop...

This is really incredible that I was able to get so close to native loop performance and is a big win for code readability.  Query chains remain understandable even with 10+ query operators chained together, but throw together a couple filters and mappings plus a sort (or two!) and the set of for loops you need to write to match it can get pretty gnarly.  Lodash is proof people are willing to sacrifice a great deal of performance to get more readable code (see benchmark results above), even in tight loops where it matters most, but it's even better if you don't have to. :smiley_cat:
  • Last Edit: November 20, 2018, 02:14:13 am by Fat Cerberus
miniSphere 5.3-beta1 (stable: 5.2.13) - Cell compiler - SSj debugger
forum thread | on GitHub

  • Radnen
  • [*][*][*][*][*]
  • Senior Staff
  • Wise Warrior
Re: miniSphere 5.3b1 (stable: 5.2.13)
Reply #2224
I'm still baffled the widespread popularity of lodash... when libraries you and I write can be an order of magnitude faster, and any missing convenience methods lodash has, can always be added.

Anyways, I didn't have from.js on me, but I ran your parameters on my new Linkier library along with lazy and Link and got:
Code: ('js') [Select]
const Linkier = require('./linkier.js');
const Link = require('./modules/link.js');
const Lazy = require('./modules/lazy.js');
const Benchmark = require('benchmark');

// Generate a random list of 100,000 integer between 0 and 1,000.
const items = [];
for (let i = 0; i < 100000; ++i) {
    items[i] = Math.floor(Math.random() * 1001);
}

const suite = new Benchmark.Suite;
const linkier = Linkier(items).filter(n => n % 2 === 0).take(10000).map(n => n + 1);
const link = Link(items).filter(n => n % 2 === 0).take(10000).map(n => n + 1);
const lazy = Lazy(items).filter(n => n % 2 === 0).take(10000).map(n => n + 1);

suite.add('Linkier', function() {
    linkier.reduce((a, n) => a + n, 0);
}).add('Link', function() {
    link.reduce((a, n) => a + n, 0);
}).add('Lazy', function() {
    lazy.reduce((a, n) => a + n, 0);
}).add('For Loop', function() {
    let n = 0;
    let r = 0;
    for (let i = 0; i < items.length; ++i) {
        if (items[i] % 2 === 0) {
            n++;
            if (n <= 10000) {
                const m = items[i] + 1;
                r = r + m;
            }
        }
    }
}).add('For Loop 2', function() {
    let n = 0;
    let r = 0;
    for (let i = 0; i < items.length; ++i) {
        if (items[i] % 2 === 0) {
            n++;
            if (n <= 10000) {
                const m = items[i] + 1;
                r = r + m;
            } else {
                break;
            }
        }
    }
}).on('cycle', (event) => {
    console.log(String(event.target));
}).on('complete', function() {
    console.log('Fastest is: ' + this.filter('fastest').map('name'));
}).run({ async: true });

Code: [Select]
Linkier x 4,242 ops/sec ±5.49% (78 runs sampled)
Link x 3,786 ops/sec ±2.13% (91 runs sampled)
Lazy x 2,917 ops/sec ±2.87% (91 runs sampled)
For Loop x 2,213 ops/sec ±2.01% (96 runs sampled)
For Loop 2 x 11,052 ops/sec ±1.52% (97 runs sampled)
Fastest is: For Loop 2

What we learn here, is that hand-writing a for loop can be slower... The first for loop doesn't short circuit after 10,000 items, but that's on intention. How many times in writing a for loop you think of doing that? Therefore from.js, link.js and other libraries are going to be faster since they can make those common-sense decisions for you, and just automatically make your code faster.
If you use code to help you code you can use less code to code. Also, I have approximate knowledge of many things.

Sphere-sfml here
Sphere Studio editor here

  • Fat Cerberus
  • [*][*][*][*][*]
  • Global Moderator
  • miniSphere Developer
Re: miniSphere 5.3b2 (stable: 5.2.13)
Reply #2225
miniSphere 5.3 release is very close - just a few more API kinks I have to work out but otherwise everything is ready to go.

I even made a last-minute API addition: you'll be able to create custom BlendOps to have better control over the blending stage of the graphics pipeline.  This is something that can't be handled in the fragment shader at all--blending is still fixed-function even on modern hardware.
miniSphere 5.3-beta1 (stable: 5.2.13) - Cell compiler - SSj debugger
forum thread | on GitHub