# Am I doing this right?

**URL:** <https://forum.vassalengine.org/t/am-i-doing-this-right/10935>\
**Category:** Development\
**Created:** [July 28, 2020, 5:34pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935 "2020-07-28T17:34:42Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![Cattlesquat](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cattlesquat/32/241_2.png) [@Cattlesquat](https://forum.vassalengine.org/u/Cattlesquat)\
**Post date:** [July 28, 2020, 5:34pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/1 "2020-07-28T17:34:42Z")

</div>

Flint1b – I did the git commands below and couldn’t tell any difference, so I think maybe I’m not building correctly or maybe I’m on the wrong branch or something? Brian

git fetch upstream pull/75/head:Try75  
git checkout Try75

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [July 28, 2020, 5:38pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/2 "2020-07-28T17:38:58Z")

</div>

Thus spake Cattlesquat:

> Flint1b – I did the git commands below and couldn’t tell any  
> difference, so I think maybe I’m not building correctly or maybe I’m on  
> the wrong branch or something? Brian
> 
> git fetch upstream pull/75/head:Try75  
> git checkout Try75

Does ‘git log’ show the same commit at HEAD for your Try75 branch  
as the last commit on the PR on GitHub?

–  
J.

---

<div class="post-metadata">

**Author:** ![Cattlesquat](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cattlesquat/32/241_2.png) [@Cattlesquat](https://forum.vassalengine.org/u/Cattlesquat)\
**Post date:** [July 28, 2020, 5:41pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/3 "2020-07-28T17:41:41Z")

</div>

It shows the same commit message as the last commit message in the list (“save property map instead of piece clone as snapshot”).  
There’s a force-push listed in the PR below the commit that isn’t shown, but not sure it’s supposed to.

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [July 28, 2020, 5:47pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/4 "2020-07-28T17:47:28Z")

</div>

Thus spake Cattlesquat:

> It shows the same commit message as the last commit message in the list  
> (“save property map instead of piece clone as snapshot”).  
> There’s a force-push listed in the PR below the commit that isn’t shown,  
> but not sure it’s supposed to.

As that’s the only commit in PR 75, if that’s HEAD on your Try75 branch  
and you’re on your Try75 branch, then you’ve got the PR checked out.

–  
J.

---

<div class="post-metadata">

**Author:** ![Cattlesquat](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cattlesquat/32/241_2.png) [@Cattlesquat](https://forum.vassalengine.org/u/Cattlesquat)\
**Post date:** [July 28, 2020, 5:54pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/5 "2020-07-28T17:54:56Z")

</div>

Well dang. All that seems to be true. I wonder why I’m not seeing any perf increase.

---

<div class="post-metadata">

**Author:** ![Flint1b](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/flint1b/32/246_2.png) [@Flint1b](https://forum.vassalengine.org/u/Flint1b)\
**Post date:** [July 28, 2020, 6:35pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/6 "2020-07-28T18:35:05Z")

</div>

Hmm… when I try this first module with current master, add 4-5 of each piece to the map, right click and count, it takes about 2-3 seconds. When I try the same with this PR, it only takes about 1 second. And I get similar relative results with the second module.

---

<div class="post-metadata">

**Author:** ![Cattlesquat](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cattlesquat/32/241_2.png) [@Cattlesquat](https://forum.vassalengine.org/u/Cattlesquat)\
**Post date:** [July 28, 2020, 7:14pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/7 "2020-07-28T19:14:37Z")

</div>

> [@Flint1b](#):
>
> Hmm… when I try this first module with current master, add 4-5 of each piece to the map, right click and count, it takes about 2-3 seconds. When I try the same with this PR, it only takes about 1 second. And I get similar relative results with the second module.

Oh wow. With current master the test case you describe is “effectively instantaneous” so I see why I’m confused.

Also that gives me a whole new impression of your earlier statement that “Paths of Glory runs like a dog” 😮 I’m horrified to even think!

---

<div class="post-metadata">

**Author:** ![m3tan](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/m3tan/32/229_2.png) [@m3tan](https://forum.vassalengine.org/u/m3tan)\
**Post date:** [July 28, 2020, 7:29pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/8 "2020-07-28T19:29:15Z")

</div>

> [@Cattlesquat](#):
>
> Also that gives me a whole new impression of your earlier statement that “Paths of Glory runs like a dog” 😮 I’m horrified to even think!

And this is why I choose not to drink from the firehose…

---

<div class="post-metadata">

**Author:** ![Cattlesquat](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cattlesquat/32/241_2.png) [@Cattlesquat](https://forum.vassalengine.org/u/Cattlesquat)\
**Post date:** [July 28, 2020, 7:32pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/9 "2020-07-28T19:32:36Z")

</div>

Naw, ya gotta drink! Who’s ever worked as a professional developer and not suddenly found out their thing breaks/lags/etc on some other computer or in some other use case and had to fix something? This is how Vassal gets better!

---

<div class="post-metadata">

**Author:** ![Cattlesquat](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cattlesquat/32/241_2.png) [@Cattlesquat](https://forum.vassalengine.org/u/Cattlesquat)\
**Post date:** [July 28, 2020, 7:37pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/10 "2020-07-28T19:37:44Z")

</div>

But anyway, Flint1b – now drill down on those modules under YOUR branch and see if you can speed up Global Key Commands themselves!

---

<div class="post-metadata">

**Author:** ![Flint1b](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/flint1b/32/246_2.png) [@Flint1b](https://forum.vassalengine.org/u/Flint1b)\
**Post date:** [July 28, 2020, 8:30pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/11 "2020-07-28T20:30:00Z")

</div>

> [@Cattlesquat](#):
>
> Oh wow. With current master the test case you describe is “effectively instantaneous” so I see why I’m confused.
> 
> Also that gives me a whole new impression of your earlier statement that “Paths of Glory runs like a dog” 😮 I’m horrified to even think!

I think Brent said this with the dog but yea on my computer it’s very slow. I am so used to getting a top notch computer from my employers that I don’t bother getting a fast and expensive one for myself, as long as I can watch youtube, netflix, play the occasional game and run ms-dos and windows emulators for old games, I’m happy.

That one module I play in PBEM, it does load somewhat faster than Paths of Glory, but I already made it a habit getting a drink while it loads up the opponents log, when I come back it has loaded the counters and almost finished loading the map.

---

<div class="post-metadata">

**Author:** ![Flint1b](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/flint1b/32/246_2.png) [@Flint1b](https://forum.vassalengine.org/u/Flint1b)\
**Post date:** [July 28, 2020, 9:49pm UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/12 "2020-07-28T21:49:04Z")

</div>

For the reference, when I run Paths of Glory 9.8 on Vassal 3.3.2:

- start wizard, select “new game”, then “deluxe map something blabla”, then it loads for ~33 seconds until I can continue
- then continue (next/finish, whichever works)
- then the Player starts loading and loads for about 2:20min until it finishes loading and the CPU usage goes down

All this time, the CPU usage is often below 80% on one core, and almost no CPU usage on the other 3 cores. Rarely, it goes to 100% on a single core, even more rare is when 2 cores are used up to 100%. And that is not due to I/O, there’s hardly any I/O happening during this time.

As a comparison, when I load up Minecraft all 4 CPU cores go up to almost 100% until it’s finished loading.

This must be the result of glorious single-thread processing in the AWT event thread, and a model that processes complex things in a recursive manner. I took a look at how these global key thingies work, it’s all recursive, I see no way of turning that into parallel processing to make use of all CPU cores.

The doctor suggests slaughtering this thing, taking out whatever parts are useful, and recycling them within a rewrite, in Java, with JavaFX. And including the old code into the new one and offering a “legacy mode” for the modules whose developers are too lazy to adapt modules to new version 😃

---

<div class="post-metadata">

**Author:** ![Flint1b](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/flint1b/32/246_2.png) [@Flint1b](https://forum.vassalengine.org/u/Flint1b)\
**Post date:** [July 29, 2020, 2:32am UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/13 "2020-07-29T02:32:56Z")

</div>

> [@Cattlesquat](#):
>
> But anyway, Flint1b – now drill down on those modules under YOUR branch and see if you can speed up Global Key Commands themselves!

There’s also a discussion in that PR now, I’m not sure it will get merged at all, almost wishing I wouldn’t have gotten involved with a change that someone else came up with which sounded really good and I just went ahead and implemented it without fully understanding the consequences.

Anyways for my potato of a computer this change makes a huge difference and if it doesn’t get in, I will just make a custom version of Vassal for myself and use that instead of the release build. Further discussions about the PR and probably all performance optimizations in general, I give up, whoever wants it merged can take over. I’m going back into “rogue mode”, find some useful TODOs on my own and make the necessary changes.

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [July 30, 2020, 1:14am UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/14 "2020-07-30T01:14:45Z")

</div>

Thus spake Flint1b:

> For the reference, when I run Paths of Glory 9.8 on Vassal 3.3.2:
> 
> - start wizard, select “new game”, then “deluxe map something blabla”,  
> then it loads for ~33 seconds until I can continue
> - then continue (next/finish, whichever works)
> - then the Player starts loading and loads for about 2:20min until it  
> finishes loading and the CPU usage goes down

I had a look in visualvm at why things seemed so slow _after_ the module  
loaded.

What I found was 42% of the time was being spent in  
BasicModule.encodeSubCommand() while I was doing things like removing  
then Neutral Country markers, so I checked there.

private String encodeSubCommand(Command c) {  
String s = null;  
for (int i = 0; i \< commandEncoders.length && s == null; ++i) {  
s = commandEncoders[i].encode(c);  
}  
return s;  
}

If the profiling is right, we’re spending _ages_ just looping over  
these command encoders… Hmm.

–  
J.

---

<div class="post-metadata">

**Author:** ![uckelman](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/uckelman/32/10020_2.png) [@uckelman](https://forum.vassalengine.org/u/uckelman)\
**Post date:** [July 30, 2020, 1:19am UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/15 "2020-07-30T01:19:06Z")

</div>

Thus spake Joel Uckelman:

> Thus spake Flint1b:
> 
> > For the reference, when I run Paths of Glory 9.8 on Vassal 3.3.2:
> > 
> > - start wizard, select “new game”, then “deluxe map something blabla”,  
> > then it loads for ~33 seconds until I can continue
> > - then continue (next/finish, whichever works)
> > - then the Player starts loading and loads for about 2:20min until it  
> > finishes loading and the CPU usage goes down
> 
> I had a look in visualvm at why things seemed so slow _after_ the module  
> loaded.
> 
> What I found was 42% of the time was being spent in  
> BasicModule.encodeSubCommand() while I was doing things like removing  
> then Neutral Country markers, so I checked there.
> 
> private String encodeSubCommand(Command c) {  
> String s = null;  
> for (int i = 0; i \< commandEncoders.length && s == null; ++i) {  
> s = commandEncoders[i].encode(c);  
> }  
> return s;  
> }
> 
> If the profiling is right, we’re spending _ages_ just looping over  
> these command encoders… Hmm.

And also GlobalProperty.encode() was called about 15k times.

–  
J.

---

<div class="post-metadata">

**Author:** ![Cattlesquat](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cattlesquat/32/241_2.png) [@Cattlesquat](https://forum.vassalengine.org/u/Cattlesquat)\
**Post date:** [July 30, 2020, 2:18am UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/16 "2020-07-30T02:18:41Z")

</div>

Wow. To be clear deleting a Neutral Country marker is probably sending some Global Key Commands – because it wants to put the appropriate Event marker on the Turn Track, and in some cases (Bulgaria and Romania) deploy some troops from the Reinforcement Card to the map. But… 15,000 times?!

---

<div class="post-metadata">

**Author:** ![Flint1b](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/flint1b/32/246_2.png) [@Flint1b](https://forum.vassalengine.org/u/Flint1b)\
**Post date:** [July 30, 2020, 2:21am UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/17 "2020-07-30T02:21:43Z")

</div>

> [@Flint1b](#):
>
> For the reference, when I run Paths of Glory 9.8 on Vassal 3.3.2:
> 
> - then the Player starts loading and loads for about 2:20min until it finishes loading and the CPU usage goes down

With the changes from the the PieceCloner.clone() PR, this loads in about 1:00 minute.

I don’t trust the visualvm profiler, it gave me completely different results than JProfiler, and the change applied after the JProfiler result got me a huge performance increase. Profiling Java is a very complex matter and there is a reason why all the good profilers cost money.

---

<div class="post-metadata">

**Author:** ![Cattlesquat](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/cattlesquat/32/241_2.png) [@Cattlesquat](https://forum.vassalengine.org/u/Cattlesquat)\
**Post date:** [July 30, 2020, 2:29am UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/18 "2020-07-30T02:29:24Z")

</div>

Is there one that costs a couple hundred dollars that we should get?

---

<div class="post-metadata">

**Author:** ![Flint1b](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/flint1b/32/246_2.png) [@Flint1b](https://forum.vassalengine.org/u/Flint1b)\
**Post date:** [July 30, 2020, 2:41am UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/19 "2020-07-30T02:41:16Z")

</div>

The most popular high-performance minecraft server uses the YourKit profiler, it costs money but they give free licenses to open source projects if the project adds a reference to their website. I hear Vassal used to have this license already and YourKit gladly supplied it, it just wasn’t renewed at some point.

---

<div class="post-metadata">

**Author:** ![Brent\_Easton](https://forum.vassalengine.org/user_avatar/forum.vassalengine.org/brent_easton/32/10_2.png) [@Brent\_Easton](https://forum.vassalengine.org/u/Brent_Easton)\
**Post date:** [July 30, 2020, 3:04am UTC](https://forum.vassalengine.org/t/am-i-doing-this-right/10935/20 "2020-07-30T03:04:04Z")

</div>

I have emailed Yourkit requesting a new License. We will need to add a link to them back in to our project page, I have asked for details of what they need.

[Next page](https://forum.vassalengine.org/t/am-i-doing-this-right/10935.md?page=2)
