Author Topic: Silky Smooth Events Editor Closing  (Read 6546 times)

0 Members and 1 Guest are viewing this topic.

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Silky Smooth Events Editor Closing
The more adventurous FREDders amongst you will know that as a mission gets larger it takes longer and longer to close the Events Editor.

I got pissed off at a Diaspora mission taking over a minute to close the event editor, profiled FRED, found the cause and fixed it. I'll be adding this fix to SVN in a day or two but I wanted FREDders to check that it's not borking anything before I commit it (it really shouldn't be but given that the outcome if it does is ****ing up someone's mission, I figured it was worth double checking).

To test this, pick a mission. Save it under a different name. Delete an event or ship or message. Do the same in a regular FRED build. Compare the two missions using WinMerge or something similar. They should be identical apart from the save time.

For the coders, here's the patch. Yes, that's really all I did. :p

Code: [Select]
Index: parse/sexp.cpp
===================================================================
--- parse/sexp.cpp (revision 8680)
+++ parse/sexp.cpp (working copy)
@@ -25017,6 +25017,9 @@
 void update_sexp_references(const char *old_name, const char *new_name, int format)
 {
  int i;
+ if (!strcmp(old_name, new_name)) {
+ return;
+ }
 
  Assert(strlen(new_name) < TOKEN_LENGTH);
  for (i = 0; i < Num_sexp_nodes; i++)

It turns out that FRED checks that event names, message names, etc were checked using a recursive call to update_sexp_references(). Since this then checked every single SEXP node once for every single event in the game, as missions grow, the amount of calls made increases exponentially. Using a mission that took over a minute to close the event editor, I profiled it for 3 seconds and found it had made over 3 million calls to update_sexp_references. Meaning that it was probably making around 60 million calls in total when closing the event editor.

I have not fixed this behaviour.

What I fixed was it doing this when the old name and the new name were exactly the same. i.e the 99% of calls it never needed to make in the first place. :p


For the FREDders, here's the build.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline CommanderDJ

  • Software engineer
  • 210
    • Minecraft
Re: Silky Smooth Events Editor Closing
* CommanderDJ applauds.

Brilliant. Will test this later today.
« Last Edit: April 19, 2012, 03:13:44 am by CommanderDJ »
[16:57] <CommanderDJ> What prompted the decision to split WiH into acts?
[16:58] <battuta> it was long, we wanted to release something
[16:58] <battuta> it felt good to have a target to hit
[17:00] <RangerKarl> not sure if talking about strike mission, or jerking off
[17:00] <CommanderDJ> WUT
[17:00] <CommanderDJ> hahahahaha
[17:00] <battuta> hahahaha
[17:00] <RangerKarl> same thing really, if you think about it

 

Offline Mongoose

  • Rikki-Tikki-Tavi
  • Global Moderator
  • 212
  • This brain for rent.
    • Minecraft
    • Steam
    • Something
Re: Silky Smooth Events Editor Closing
I have not fixed this behaviour.

What I fixed was it doing this when the old name and the new name were exactly the same. i.e the 99% of calls it never needed to make in the first place. :p
...that has to be the very definition of Nightmare Code. :lol:

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Silky Smooth Events Editor Closing
Well basically the problem never existed in Volition missions since they were so small. No one spotted that the code was doing unnecessary function calls as a result.

Hell, for all I know, I might actually be the first person to ever profile FRED. Usually we don't care about minor problems with FRED being slow.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Fury

  • The Curmudgeon
  • 213
Re: Silky Smooth Events Editor Closing
Would you consider enabling "show ship models" by default because a lot of people don't seem to realize that the wireframe view slows down rendering to crawl?

 

Offline Spoon

  • 212
  • ヾ(´︶`♡)ノ
Re: Silky Smooth Events Editor Closing
Incredible, its not even been a day since I made that not so serious complaint thread about this.
Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them

 

Offline Legate Damar

  • Keeping up with the Cardassians
  • 29
  • Hail Cardassia!
Re: Silky Smooth Events Editor Closing
Incredible, its not even been a day since I made that not so serious complaint thread about this.

You have lots of influence, it seems.

Will this be included in 3.6.14 final?

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Silky Smooth Events Editor Closing
If enough people test it and report back that it doesn't **** things up, maybe.

And actually it wasn't cause of Spoon. I added 30 events to a mission recently which pushed it over the edge from annoying to downright anger inducing. I happened to have set up profiling builds for Diaspora earlier this week for unrelated reasons so basically this was the first time that I've had time to fix the problem, a build already set up to do it with, and a mission that was displaying the behaviour at the same time.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Spoon

  • 212
  • ヾ(´︶`♡)ノ
Re: Silky Smooth Events Editor Closing
You have lots of influence, it seems.
lol no, this was purely coincidence
Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them

 

Offline jg18

  • A very happy zod
  • 210
  • can do more than spellcheck
Re: Silky Smooth Events Editor Closing
Nicely done and well-timed, too.

It's a nice shortcut that you know for a fact can save you a lot of unnecessary work since you profiled first. :)

How long did it take to close the events editor after you added the shortcut, btw?

A few thoughts:

(1) Is the growth really exponential? Whatever it is, it's obviously fast, and although I'm not (yet) familiar with the SEXP handling code, I'd think that the amount of checking would be
O(<number of SEXP nodes> x <number of events>).

(2) About the patch itself, you may want to adjust the patch as follows:

(a) Put the three lines you added above the
Code: [Select]
int i; line, to make it clear that that declaration fits with the rest of the code and not your new shortcut.

(b) Add a comment above your added lines, maybe
Code: [Select]
// If the name hasn't changed, there's nothing to update
(c) Move the assert to the top of the function, so that it checks the assert before evaluating your shortcut.

(d) Maybe even move the index variable i into the for loop, something :v: couldn't do in C but that can done in C++, making the line read

Code: [Select]
for (int i = 0; i < Num_sexp_nodes; i++)
(I'm not backseat coding, I swear. :nervous:)

EDIT: Slight corrections.
« Last Edit: April 19, 2012, 05:09:49 pm by jg18 »

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Silky Smooth Events Editor Closing
I would move the declaration but it's a style thing. Everyone keeps using the uninitialised, right at the top of the function declaration style which means that I have to too.

We don't move the loop variables for instance cause we end up breaking compilation on VC6 whenever we do (VC6 has this rather stupid standard where you could then access i outside the loop. Meaning if anyone ever added a second loop to the function and re-used i, it would break compilation).

I didn't move the assertion cause if the names are the same, we really should be catching it earlier. The old name would have been broken for a long time.

Growth isn't really exponential but it is pretty big, permit me some hyperbole. :p

As for adding a comment. Never had a problem with that. :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Echelon9

  • Moderator
  • 210
Re: Silky Smooth Events Editor Closing
Yeh, looks good with those slight tweaks. Nice work karajorma.

 

Offline jg18

  • A very happy zod
  • 210
  • can do more than spellcheck
Re: Silky Smooth Events Editor Closing
I would move the declaration but it's a style thing. Everyone keeps using the uninitialised, right at the top of the function declaration style which means that I have to too.
I think in ANSI C (specifically C89), local variables have to be declared at the top of the function (or code block) in which they're used, which is probably why :v: did things that way. C99 and C++ don't have that requirement, in which case it becomes a matter of style. As you can see, I like keeping related statements together, but that's just me. :)

 

Offline Cyborg17

  • 29
  • Life? Don't talk to me about life....
Re: Silky Smooth Events Editor Closing
Thank you!  :)

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Silky Smooth Events Editor Closing
I think in ANSI C (specifically C89), local variables have to be declared at the top of the function (or code block) in which they're used, which is probably why :v: did things that way. C99 and C++ don't have that requirement, in which case it becomes a matter of style. As you can see, I like keeping related statements together, but that's just me. :)

Oh trust me, I bloody hate the way things are done now. Increasing the scope of variables in that way is just going to cause unnecessary bugs. But that's the style. So unless we decide to change the style, it's not something one or two coders should just independently decide to change.

Especially when as I say, it can cause the code not to compile on other IDEs.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline chief1983

  • Still lacks a custom title
  • Moderator
  • 212
  • ⬇️⬆️⬅️⬅️🅰➡️⬇️
    • Minecraft
    • Skype
    • Steam
    • Twitter
    • Fate of the Galaxy
Re: Silky Smooth Events Editor Closing
Yes, please don't put the 'int i' inside a for loop declaration.
Fate of the Galaxy - Now Hiring!  Apply within | Diaspora | SCP Home | Collada Importer for PCS2
Karajorma's 'How to report bugs' | Mantis
#freespace | #scp-swc | #diaspora | #SCP | #hard-light on EsperNet

"You may not sell or otherwise commercially exploit the source or things you created based on the source." -- Excerpt from FSO license, for reference

Nuclear1:  Jesus Christ zack you're a little too hamyurger for HLP right now...
iamzack:  i dont have hamynerge i just want ptatoc hips D:
redsniper:  Platonic hips?!
iamzack:  lays

 

Offline Spoon

  • 212
  • ヾ(´︶`♡)ノ
Re: Silky Smooth Events Editor Closing
Initial tests have shown no problems for me so far
Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them

 

Offline Spoon

  • 212
  • ヾ(´︶`♡)ノ
Re: Silky Smooth Events Editor Closing
So after using it for some time now, I have not experienced any wierdness or troubles with this change in the event editor.
Not sure if any more feedback is required on this, since the last reply was from me, and it was a while ago but hey.
Urutorahappī!!

[02:42] <@Axem> spoon somethings wrong
[02:42] <@Axem> critically wrong
[02:42] <@Axem> im happy with these missions now
[02:44] <@Axem> well
[02:44] <@Axem> with 2 of them

 

Offline mjn.mixael

  • Cutscene Master
  • 212
  • Chopped liver
    • Steam
    • Twitter
Re: Silky Smooth Events Editor Closing
So after using it for some time now, I have not experienced any wierdness or troubles with this change in the event editor.
Not sure if any more feedback is required on this, since the last reply was from me, and it was a while ago but hey.

Quote'd for truth.
Cutscene Upgrade Project - Mainhall Remakes - Between the Ashes
Youtube Channel - P3D Model Box
Between the Ashes is looking for committed testers, PM me for details.
Freespace Upgrade Project See what's happening.

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Silky Smooth Events Editor Closing
Well it's been in trunk for a while now and no one has reported any issues with it. So hopefully the fix is good enough. :)
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]