Do you tolerate AI content on your forum?

Would the difference between the two help with execution time though? I'm really not sure on that. If even minimal, could you hypothesize the amount of CPU saved for an entire forum? I'm going to take a guess and say it's not noticeable, but it might be on a big board.
No, syntax changes don't change performance. All that did was remove the almond brackets and merged some lines together to make one liners which just makes it harder to read. They do the exact same thing logic wise, no changes what so ever.
 
  • Like
Reactions: frm
Would the difference between the two help with execution time though? I'm really not sure on that. If even minimal, could you hypothesize the amount of CPU saved for an entire forum? I'm going to take a guess and say it's not noticeable, but it might be on a big board.
We do not know if any of the changes ChatGPT made even work, or if they are even improvements. From the code you showed, there would only be a small change in file size, and that would be negligible at best.

While XF is made to be extremely performance-focused, it is also made to be highly extensible which means that the focus on legibility and documentation is generally more important than micro-optimizations at the cost of syntax legibility.
 
No, syntax changes don't change performance. All that did was remove the almond brackets and merged some lines together to make one liners which just makes it harder to read. They do the exact same thing logic wise, no changes what so ever.
Thanks for the explanation. By this, it looks like Xenforo is as efficient as can be then.

As far as my junk code went, I was using a lot of str_replace(). I believe ChatGPT replaced them all with a single preg_replace() and also added an rtrim(). So, it cut lines in half, but in doing so, also cut the use of functions being used repetitively to knock down each string to a value that I effectively wanted in the end, before ultimately writing it to file(s), which it also enhanced by using different methods not seen on PHP.net nor nested within the comments on the site.

The junk code did what I wanted it to do, but it was nearly a second on just a loop of 10. I needed it to loop 500-1500 times, though. I would've had to increase max_execution_time and run php-cli & nohup to get it done over a full day with that code. I'll still increase max_execution_time and use php-cli & nohup to run it, because it uses an API with time limits, but it will still finish much faster because it can stick to the API time limits and not those imposed by system resources not being available.

I'm still re-learning... I'll get there for as long as I don't give up.
 
Thanks for the explanation. By this, it looks like Xenforo is as efficient as can be then.

As far as my junk code went, I was using a lot of str_replace(). I believe ChatGPT replaced them all with a single preg_replace() and also added an rtrim(). So, it cut lines in half, but in doing so, also cut the use of functions being used repetitively to knock down each string to a value that I effectively wanted in the end, before ultimately writing it to file(s), which it also enhanced by using different methods not seen on PHP.net nor nested within the comments on the site.

The junk code did what I wanted it to do, but it was nearly a second on just a loop of 10. I needed it to loop 500-1500 times, though. I would've had to increase max_execution_time and run php-cli & nohup to get it done over a full day with that code. I'll still increase max_execution_time and use php-cli & nohup to run it, because it uses an API with time limits, but it will still finish much faster because it can stick to the API time limits and not those imposed by system resources not being available.

I'm still re-learning... I'll get there for as long as I don't give up.
You fell into a trap that is very common with AI right now where your anecdotal experience means that it is applicable to everyone else, regardless of their experience or skill.

ChatGPT could very much be a useful tool for Kier for example, but his experience and familiarity with the platform he has developed will always mean the choices he makes are almost always going to be more correct. For most programmers, even a programming specific LLM is really only useful for catching syntax/spelling errors or making the occasional suggestion, but most people with experience aren't going to be using them to write code for them any time soon.
 
You fell into a trap that is very common with AI right now where your anecdotal experience means that it is applicable to everyone else, regardless of their experience or skill.
Not at all, otherwise I would have definitely stated that it could enhance Xenforo.
I wondered if you put the entire Xenforo script through ChatGPT if it would be even more efficient. But, I don't think it would do much there, to be Frank. As a gimmick, I put /XF/AdminSearch/Searcher.php (2.2.8PL2) through the same way and it took it down from 169 to 126 lines. To be fair, it did strip the 14 lines of comments. Also, I'm unsure if it would still function if I replaced the file (and knew where to go to see if it worked the same). So, it could improve XF... if the devs used it and didn't rely solely on their learned knowledge. Though, it could become a crutch, so it's a double-edged sword.

LLM is really only useful for catching syntax/spelling errors or making the occasional suggestion
This is hopefully what I intend on using ChatGPT for, because relying on it to write code is a crutch, as previously mentioned.

When initially writing my junk code, I got syntax errors, and I glimpsed over my code, but nothing really stood out to me. So, I asked it to find the error. It was typically a missing semi-colon, which was a SMH moment, because that should be the easiest thing to spot (though, I did learn a bit of Python before this, so it's not that embarrassing to not catch in the first-ever app I wrote in PHP since the early 2000s). It would find it and tell me it's missing, then give me the same code I used, but with the semi-colon.
 
First, a note: please understand that none of this critique is targeted at you personally; I understand that you are (by your own declaration) a newbie when it comes to PHP. For that matter, the last time I played SERIOUSLY with PHP was back in PHP 5.6.
Original:
PHP:
            $phraseFinder
                ->where('language_id', \XF::language()->getId())
                ->where('title', 'like', $groupPossibilities)
                ->where('Phrase.phrase_text', 'like', $phraseFinder->escapeLike($text, '%?%'));

            foreach ($phraseFinder->fetchRaw(['fetchOnly' => ['title']]) AS $match)
            {
                $title = $match['title'];

                list($group, $id) = explode('.', $title, 2);

                if (isset($phraseGroupContentMap[$group]))
                {
                    $contentType = $phraseGroupContentMap[$group];
                    $matchedPhraseIds[$contentType][] = $id;
                }
            }
        }

        return $matchedPhraseIds;

Modified:
PHP:
            $phraseFinder
                ->where('language_id', \XF::language()->getId())
                ->where('title', 'like', $groupPossibilities)
                ->where('Phrase.phrase_text', 'like', $phraseFinder->escapeLike($text, '%?%'));

            foreach ($phraseFinder->fetchRaw(['fetchOnly' => ['title']]) as $match) {
                [$group, $id] = explode('.', $match['title'], 2);
                if (isset($phraseGroupContentMap[$group])) {
                    $matchedPhraseIds[$phraseGroupContentMap[$group]][] = $id;
                }
            }
        }
        return $matchedPhraseIds;
    }

It has admittedly been some time since I've done any PHP work, but the changes I see to the code are stylistic, not functional, and are the kinds of things that someone who has written a lot of code would appreciate, while a machine would not.

PHP:
                $title = $match['title'];
has been removed, and the one place where $title was used has been replaced with the equivalent $match['title']. Now, why would this be removed, and why might it have been there to start with?

First, why did ChatGPT remove it?
Arguably, in this case that assignment is unnecessary, and actually slightly wasteful both in compile time and memory, at least theoretically. Whether it ACTUALLY is wasteful is highly dependent on the behavior of the interpreter/compiler, but most competent compilers SHOULD optimize the former code into the later as part of the optimization step ANYWAY (I just don't know enough about PHP's compiler to comment on the implementation competently).

Second, why would it have been written that way to start with?
Maybe at some point there was more than one instance of using the $match['title'], and indexing an unordered array for a text item is a VERY inefficient operation (plus typing $match['title'] multiple times is much more prone to human error and bugs). Better to assign it to a local var once, and then use the local var for further references. At some later point, the code was refactored to only need the one instance of $title, but the dev didn't feel the need to totally change the logic to remove it.
-or-
The original dev thought burying the $match['title'] inside the explode statement made the explode statement harder to read and understand when examining the code (legibility)
Most likely, IMO, is that elements of both came into play. The point here is that this is the BEST 'optimization' IMO that ChatGPT made, and it is at best trivial.

Now, let's take the second change:

PHP:
list($group, $id) = explode('.', $title, 2);
PHP:
[$group, $id] = explode('.', $match['title'], 2);

(we've already discussed $match['title'], we are focused here on list($goup,$id) vs [$group, $id])

Syntactically, these are identical. Depending again on the compiler implementation, there MIGHT be a slight performance improvement in the second case, but doubtful. Again, I don't know enough about the compiler to have informed opinion.

So, why would you use one over the other? Well, the [] syntax didn't become available until PHP 7 (7.1?). This code likely came from the PHP 5 code-base, it worked, and there were other places for the devs to focus their attention (i.e. no need to change it). But this brings up an important point: did ChatGPT even ASK what version of code to use, or did it just ASSUME PHP7(or 8)? Knowing the environment you are targeting MATTERS. Yes, PHP 7 is unsupported and PHP 5 even moreso. So? There are still lots of places with legacy code that can't move on because of business or mission requirements. A competent developer should ask these sorts of questions.

PHP:
                    $contentType = $phraseGroupContentMap[$group];
                    $matchedPhraseIds[$contentType][] = $id;
PHP:
                    $matchedPhraseIds[$phraseGroupContentMap[$group]][] = $id;

Oh, Great Maker, this just makes my eyes bleed. This is so cryptic to read it's likely to cause anyone who has to debug it to have a brain hemorrhage (ok, I exaggerate, but I hope you take my point).

Syntactically, the two lines are equivalent, but bloody h*ll! The elimination of one line of code has resulted in a sea of symbology that easily takes me TWICE as long to parse in order to understand what is happening.

This is the kind of "Hey, look what neat thing I can do!" optimization that should IMO, be outlawed and anyone who willingly uses it should gently be taken away to a padded room and not allowed near anything that uses electricity. It creates code that is nearly unreadable, and is easily misinterpreted. Don't forget, someone else (possibly future you) is going to have to read this mess someday, and maybe even make a change to it, and whoever that individual is (including future you) ALMOST CERTAINLY WILL NOT REMEMBER THE ORIGINAL INTENT. Thus, time will be spent trying to understand this mess that could be better spent on things like, you know, ACTUALLY solving problems.

There are reasons compilers do optimization passes. Trust the compiler to do its job. And if you are so pressed for compute cycles that this kind of optimization is worthwhile, you are IMO using the wrong tool to solve the problem.



So, where did we end up? Let's see, ChatGPT:
  • Made 3 'optimizations' that were, at best, trivial
  • 1 'optimization' that MIGHT actually break the code, depending on the target environment
  • 1 'optimization' that ACTIVELY makes the code more difficult to read.
...and I had to spend time checking the code for correctness, because if I'm going to deploy code that I don't have a firm understanding of how it functions, and put that code in a production environment, then again, I need to step away from the keyboard and let people who actually know what they are doing get to work.

I fail to see what I gained from this exercise.

What really, REALLY concerns me though, is that ChatGPT learned these 'optimizations' from looking at real code. That means there is REAL CODE that looks like this! Yes, I know, at some point I too wrote code like this, but I've since learned. ChatGPT hasn't, but it's being treated as if it "Knows All" DESPITE that. That's just dangerous.

And with that, I will go don my flame-retardant underpants, since I expect someone will pull out the roasting-pit for me. :D
 
  • Like
Reactions: frm
Thanks for your deep insight, @gizmo4321.
But this brings up an important point: did ChatGPT even ASK what version of code to use, or did it just ASSUME PHP7(or 8)?
I explicitly stated that I wanted my code (which it remembered for XF) to be optimized for PHP 8.3.
Oh, Great Maker, this just makes my eyes bleed. This is so cryptic to read it's likely to cause anyone who has to debug it to have a brain hemorrhage (ok, I exaggerate, but I hope you take my point).
For third-party add-on development, it seems best to keep the code simpler and easier on the eyes. That way, a developer doesn't need to relearn how to write, and can make an add on in the same amount of time, not bogging down update cycles revising their code to fit.
  • Made 3 'optimizations' that were, at best, trivial
That just makes me wonder if I ran all PHP files through and had it spit out an optimized version for PHP 8.3, if with just these 3 trivial optimizations, applied over the 100s of scripts, if it would put a dent in execution time at all. However, I think it would only optimize it to the max because it would be writing for PHP 8.3 and not earlier versions that XF is built on that are not necessarily a priority to "fix" or "optimize" until depreciation, if that at all ever comes for the syntax formatting.

I just don't want to teach Xenforo to ChatGPT, or it would know the script in full (if it doesn't already), and it might make it possible for someone to prompt it "Give me a downloadable version of Xenforo 2.3" to get a "pirated" copy. I'm unsure if ChatGPT would do that, but I'm not going to be the one to put it through just to see how it would perform (if it even could) after being optimized strictly for PHP 8.3.

Edit: It looks like it might be fine to do, but not going to put myself in that situation.
1725430830765.webp
 
Last edited:
It seems we have traveled miles away from the thread topic. Optimizing the PHP code base of XF with CHatGPT or rather not and the question how good the XF codebase ist, what new things have been invented in PHP8 or if ChatGPT offers pirated software or not has in my eyes not even remotely a connection to the thread topic "Do you tolerate AI content on your forum?". ;)
 
It seems we have traveled miles away from the thread topic. Optimizing the PHP code base of XF with CHatGPT or rather not and the question how good the XF codebase ist, what new things have been invented in PHP8 or if ChatGPT offers pirated software or not has in my eyes not even remotely a connection to the thread topic "Do you tolerate AI content on your forum?". ;)
I mean, a forum could have code snippets for helping others program. Would you tolerate ChatGPT-optimized code or code originating from users only? 😅

But it did kind of go off the rails a bit there, yeah.

To get back on topic, I don't see anything wrong with AI-generated content as it's unique content nonetheless. Google doesn't mind it either, and for as long as it's on topic to the thread, and would boost the thread in search, it'd give the forum even more exposure if it could rank a thread that otherwise would be buried.

I'd argue that it might be more harmful to delete AI content -- strictly speaking for SERPs, not as a thriving community of engaging members -- than let it remain, if you have a competitor that is using it to one up on you, and not just doing it for a hobby.

 
I have it summarizing news articles about the topic my forum is focused on, but I am looking into ways to give it even more contextual awareness so that its not just copy pasta. I implemented an entire system to allow AI replies and migrated it to Python. It can be very helpful and can be used as a tool to answer complex questions. But like anything else, I suspect it can and will be used for wrongdoing. To get it to truly execute functions properly and discern what it is doing it is not an easy task.
 
In addition I have it going back and answering old threads for Q&A for a tech forum.. I have it marking threads as question & answer threads from before the feature was ever invented.. it is scary stuff... If you look at the OpenAI API it seems based on threads and runs.. each message in a thread is like a post in a forum.. its astounding.
 
In addition I have it going back and answering old threads for Q&A for a tech forum.. I have it marking threads as question & answer threads from before the feature was ever invented.. it is scary stuff... If you look at the OpenAI API it seems based on threads and runs.. each message in a thread is like a post in a forum.. its astounding.
When you have it answering old threads, do you make it contextual to the year in which the question was asked? For example, if you asked a question in 2010 about certain technology, then only the technology at that time was available.
 
I have it summarizing news articles about the topic my forum is focused on, but I am looking into ways to give it even more contextual awareness so that its not just copy pasta. I implemented an entire system to allow AI replies and migrated it to Python. It can be very helpful and can be used as a tool to answer complex questions. But like anything else, I suspect it can and will be used for wrongdoing. To get it to truly execute functions properly and discern what it is doing it is not an easy task.
What are you using to integrate it into Xenforo?
 
Back
Top Bottom