• Log InLog In
  • Register
Liquid`
Team Liquid Liquipedia
EDT 05:40
CEST 11:40
KST 18:40
  • Home
  • Forum
  • Calendar
  • Streams
  • Liquipedia
  • Features
  • Store
  • EPT
  • TL+
  • StarCraft 2
  • Brood War
  • Smash
  • Heroes
  • Counter-Strike
  • Overwatch
  • Liquibet
  • Fantasy StarCraft
  • TLPD
  • StarCraft 2
  • Brood War
  • Blogs
Forum Sidebar
Events/Features
News
Featured News
TL.net Map Contest #21: Voting10[ASL20] Ro4 Preview: Descent11Team TLMC #5: Winners Announced!3[ASL20] Ro8 Preview Pt2: Holding On9Maestros of the Game: Live Finals Preview (RO4)5
Community News
Chinese SC2 server to reopen; live all-star event in Hangzhou16Weekly Cups (Oct 13-19): Clem Goes for Four0BSL Team A vs Koreans - Sat-Sun 16:00 CET6Weekly Cups (Oct 6-12): Four star herO85.0.15 Patch Balance Hotfix (2025-10-8)80
StarCraft 2
General
Chinese SC2 server to reopen; live all-star event in Hangzhou RotterdaM "Serral is the GOAT, and it's not close" Weekly Cups (March 17-23): Clem Bounces Back DreamHack Open 2013 revealed The New Patch Killed Mech!
Tourneys
$1,200 WardiTV October (Oct 21st-31st) SC2's Safe House 2 - October 18 & 19 INu's Battles #13 - ByuN vs Zoun Tenacious Turtle Tussle Sparkling Tuna Cup - Weekly Open Tournament
Strategy
Custom Maps
Map Editor closed ?
External Content
Mutation # 496 Endless Infection Mutation # 495 Rest In Peace Mutation # 494 Unstable Environment Mutation # 493 Quick Killers
Brood War
General
Is there anyway to get a private coach? BW General Discussion BGH Auto Balance -> http://bghmmr.eu/ BSL Season 21 OGN to release AI-upscaled StarLeague from Feb 24
Tourneys
300$ 3D!Community Brood War Super Cup #4 [ASL20] Semifinal B Azhi's Colosseum - Anonymous Tournament [Megathread] Daily Proleagues
Strategy
Current Meta Roaring Currents ASL final [I] Funny Protoss Builds/Strategies BW - ajfirecracker Strategy & Training
Other Games
General Games
Path of Exile Nintendo Switch Thread Stormgate/Frost Giant Megathread Dawn of War IV ZeroSpace Megathread
Dota 2
Official 'what is Dota anymore' discussion LiquidDota to reintegrate into TL.net
League of Legends
Heroes of the Storm
Simple Questions, Simple Answers Heroes of the Storm 2.0
Hearthstone
Deck construction bug Heroes of StarCraft mini-set
TL Mafia
TL Mafia Community Thread SPIRED by.ASL Mafia {211640}
Community
General
US Politics Mega-thread Things Aren’t Peaceful in Palestine The Chess Thread Russo-Ukrainian War Thread Men's Fashion Thread
Fan Clubs
The herO Fan Club!
Media & Entertainment
Anime Discussion Thread Series you have seen recently... [Manga] One Piece Movie Discussion!
Sports
2024 - 2026 Football Thread TeamLiquid Health and Fitness Initiative For 2023 MLB/Baseball 2023 Formula 1 Discussion NBA General Discussion
World Cup 2022
Tech Support
SC2 Client Relocalization [Change SC2 Language] Linksys AE2500 USB WIFI keeps disconnecting Computer Build, Upgrade & Buying Resource Thread
TL Community
The Automated Ban List Recent Gifted Posts
Blogs
Our Last Hope in th…
KrillinFromwales
Certified Crazy
Hildegard
The Heroism of Pepe the Fro…
Peanutsc
Rocket League: Traits, Abili…
TrAiDoS
Customize Sidebar...

Website Feedback

Closed Threads



Active: 1084 users

The Big Programming Thread - Page 703

Forum Index > General Forum
Post a Reply
Prev 1 701 702 703 704 705 1032 Next
Thread Rules
1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution.
2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20)
3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible.
4. Use [code] tags to format code blocks.
Manit0u
Profile Blog Joined August 2004
Poland17389 Posts
Last Edited: 2016-01-22 17:47:43
January 22 2016 17:47 GMT
#14041
To anyone working with Doctrine: I've discovered a nasty bug (or maybe it's a feature) today in it.

It appears that if you do something like that...


$queryBuilder = $this->createQueryBuilder();
$expr = $queryBuilder->expr();

$query = $queryBuilder
->where($expr->like($this->getPropertyname('myField'), ':param'))
->setParameter('param', $expr->literal(sprintf('%%s%%', $myVar)))
->getQuery();

$result = $query->getResult();


... the result will be 0 rows. Always.

I've managed to fix it by de-parametrizing it and simply putting the literal expression within the where declaration. I'm still not sure if the error was trying to parametrize the "LIKE" or trying to do literal (which basically wraps your variable into single quotes) as parameter value.

Was a nasty, nasty surprise as this code was running on one of our production servers and our cron which was fetching stuff from another service was creating duplicate entries in the database because of that.
Time is precious. Waste it wisely.
tofucake
Profile Blog Joined October 2009
Hyrule19144 Posts
January 22 2016 18:19 GMT
#14042
Dump the query logs, should tell you what was happening. (please do, we are starting two new projects Symfony now)
Liquipediaasante sana squash banana
BByte
Profile Joined August 2011
Finland49 Posts
January 22 2016 19:30 GMT
#14043
On January 23 2016 02:47 Manit0u wrote:
$query = $queryBuilder
->where($expr->like($this->getPropertyname('myField'), ':param'))
->setParameter('param', $expr->literal(sprintf('%%s%%', $myVar)))
->getQuery();

$result = $query->getResult();


I've managed to fix it by de-parametrizing it and simply putting the literal expression within the where declaration. I'm still not sure if the error was trying to parametrize the "LIKE" or trying to do literal (which basically wraps your variable into single quotes) as parameter value.


Why use literal for a query parameter? Literal is needed if a parameter is not used for some reason. A parameter will be correctly escaped without a literal, and using literal might even break it, producing a query like:

...
WHERE myField LIKE ("'%my_value%'")


Also, the correct print format would presumably be '%%%s%%': https://3v4l.org/MkAhj
Manit0u
Profile Blog Joined August 2004
Poland17389 Posts
Last Edited: 2016-01-22 23:33:42
January 22 2016 20:21 GMT
#14044
On January 23 2016 04:30 BByte wrote:
Show nested quote +
On January 23 2016 02:47 Manit0u wrote:
$query = $queryBuilder
->where($expr->like($this->getPropertyname('myField'), ':param'))
->setParameter('param', $expr->literal(sprintf('%%s%%', $myVar)))
->getQuery();

$result = $query->getResult();


I've managed to fix it by de-parametrizing it and simply putting the literal expression within the where declaration. I'm still not sure if the error was trying to parametrize the "LIKE" or trying to do literal (which basically wraps your variable into single quotes) as parameter value.


Why use literal for a query parameter? Literal is needed if a parameter is not used for some reason. A parameter will be correctly escaped without a literal, and using literal might even break it, producing a query like:

...
WHERE myField LIKE ("'%my_value%'")


Also, the correct print format would presumably be '%%%s%%': https://3v4l.org/MkAhj


Oh yeah, 3x%. Sorry, was writing code as I went with the post after 17hrs at work... Still, code was fine. I just never knew that literal might have such quirks (and it appears that no one else at the office knew either).
Time is precious. Waste it wisely.
NovemberstOrm
Profile Blog Joined September 2011
Canada16217 Posts
January 23 2016 08:24 GMT
#14045
On January 22 2016 23:16 Khalum wrote:
While we're at it..
http://motherboard.vice.com/read/donald-trump-in-a-programming-language

That's great.
Moderatorlickypiddy
Manit0u
Profile Blog Joined August 2004
Poland17389 Posts
January 23 2016 08:40 GMT
#14046
On January 23 2016 03:19 tofucake wrote:
Dump the query logs, should tell you what was happening. (please do, we are starting two new projects Symfony now)


Our DB has 100GB traffic every 24h, dumping the logs would be a bad idea.

I'll post some hard-learned lessons later on so that you may avoid several pitfalls we fell into.
Time is precious. Waste it wisely.
Manit0u
Profile Blog Joined August 2004
Poland17389 Posts
January 23 2016 21:29 GMT
#14047
OK, here go some Symfony tips:

1. Dev env

Make sure to set it up properly. If you're working on Windows you're in a bit of a pickle because when your project grows your dev env is going to suck up your resources (speaking of individual developers' computers) real quick. 2GB memory limit and 300 seconds timeout settings in PHP might not be enough. This is due to Symfony in dev not only rebuilding the cache with each request but also adding additional strain (profiler toolbar, debug etc.), this means over a minute load times on each page. Surprisingly enough, it's not a problem on Linux, must have something to do with WAMP/XAMPP PHP and Apache implementations.

You can of course speed it up by using the xcache (apc for older PHP versions) and autoload dumps + optimizations. Just need to remember about rebuilding them when you add new classes. It's really easy to implement in Symfony since all you have to do is uncomment a few lines in app.php and change one use (XcacheClassLoader instead of ApcClassLoader). And a note of warning, if you're going to use several apps on the same machine you should remember about giving them different cache namespace. Easy way to do it without having to change it every time is simply doing sha1(__FILE__) instead of 'cache_namespace' in app.php. If you won't do that they'll share the namespace and will throw exceptions (cannot redeclare class).

Also, blackfire is your friend.

2. Symfony

Symfony allows you to choose one of the three methods of storing configs: annotation, yaml and xml. Performance-wise there's no difference since in the end it's compiled to pure PHP anyway so just pick one your team is most comfortable with and stick with it (try to not mix it if possible, this leads to confusion). Annotation will mean less files since both yaml and xml are stored separately but it will also be less convenient to find stuff in.

Remember to keep your user object small. It's being reloaded with every request.

Be careful with dependency injection. Especially in event listeners, which are fired with each request so injecting big services into them can hurt you a lot. Thankfully Symfony gives you the option of using lazy injection - learn it, love it.

3. Doctrine

This is the biggest Symfony bottleneck 99% of the time. If you want stuff like Redis you have to think about it from the get-go so that you can make some of your query results go to Redis without having to alter your code later on, when the app grows big and it's a pain in the ass to re-write some repository methods.

Doctrine allows you to cache 3 things: metadata, queries and results. By default it does none of them (even in the prod env!) so it rebuilds metadata cache with each request (this means parsing potentially thousands of files) which slows you down considerably. Just doing simple xcache metadata caching can give you a performance boost up to a factor of 10.

Other things that impact performance are fequent use of flushes and persists when you have to iterate over a large number of tables. Remember to flush AFTER the loop. Disabling Doctrine SqlLogger can also give you a nice boost when you have to do some heavy lifting (we have standard methods that disable the logger before doing heavy stuff and then re-enable it after it's done).

Remember to use proxies.


$post = $this->get->('app.repository.post')->find($postId);
$thread= $this->get->('app.repository.thread')->createNew();

$thread->addPost($post);

$this->entityManager->persist($thread);
$this->entityManager->flush();


This fetches entire objects. You can use proxies to set the relational data without any additional queries.


$post = $this->entityManager->getReference('App\Entity\Post', $postId);
$thread= $this->get->('app.repository.thread')->createNew();

$thread->addPost($post);

$this->entityManager->persist($thread);
$this->entityManager->flush();


Also, make sure to use EXTRA_LAZY fetches on join columns in your configs. This will tell Doctrine to not fetch all of the related objects when you query for one. It'll load them as needed.

Some articles I've found helpful (where you can get more detailed info on what I wrote above):
https://tideways.io/profiler/blog/5-ways-to-optimize-symfony-baseline-performance
http://labs.octivi.com/mastering-symfony2-performance-doctrine/

Hope this helps someone
Time is precious. Waste it wisely.
tofucake
Profile Blog Joined October 2009
Hyrule19144 Posts
January 23 2016 21:57 GMT
#14048
Might help me out some. We are building on Symfony3/PHP7/nginx on CentOS 6 vagrant boxes. Blackfire hasn't been upgraded to work with 7 yet so we're working without it for now.
Liquipediaasante sana squash banana
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
Last Edited: 2016-01-24 06:26:12
January 24 2016 06:22 GMT
#14049
Looks like Symphony and Zend Framework 2 have about the same problems.

My main gripes with ZF2:
Plugin managers that are horribly inefficient to the point that rendering a small PHP template takes 20ms since every single call to even the simplest of view helpers takes 1-2ms since it goes through the whole plugin manager chain every single time it is called. The same inefficiency is in the service locators, though at least those are called less often and so have less impact. I rewrote half the plugin manager stuff and cut the time by 90%, but I don't understand how that could happen in the first place. Actually, that's wrong, I know how that happened since I've dug in the code enough. They expect that plugins change during run time and sequential calls to the same plugin could have different results - which only makes sense to people that aren't developing actual applications.

The Event Manager is everywhere and it is sloooooow. In addition to the slowness, it also makes everything much harder to debug since you often can't see the root of the problem in the stack traces anymore. Cause the right error in a view and neither the view nor the controller will even appear in the actual stack trace. "There was an error somewhere, fix it".

Billions of includes. We wanted to run the website on the Azure cloud due to our parent company using it. Bad idea. A typical website request ended up in about 450 includes and the distributed source code storage on the cloud meant that every include took about 2ms. That was after using an optimized autoloader that used a full class map instead of looking through include directories. That didn't leave much room for performance optimization. It's much faster on the single linux server it's running on now, but I still can't understand how people manage to manufacture a framework architecture where the framework alone does 400+ includes on a single request. Architecture astronauts are killing the framework, and I thought that was an affliction reserved for AbstractSingletonFactoryPluginLocatorServiceEventManagerHelperJava programmers.

After working with Node.JS for a bit, I'm quite happy to show PHP the door and give it a kick in the back to hurry it's departure. At least for now the architecture astronauts haven't yet put their claws into it. The fact that node.js also loads everything at start time instead of request time is refreshing after trying to optimize ZF2 includes.

Some people are saying 2016 will be the year of simplification, and I say that that can't come soon enough.
Programmers need to focus on what their programs and frameworks need to do, not on what it could be used for. It's nice when the framework is flexible, but in the end it's still a web framework that is supposed to do web stuff, not guide a rocket to space. It's good when a Framework can't do everything, but instead does one job very well.
Manit0u
Profile Blog Joined August 2004
Poland17389 Posts
January 24 2016 11:07 GMT
#14050
Well, you can do fast web apps in PHP frameworks like Symfony:
http://labs.octivi.com/handling-1-billion-requests-a-week-with-symfony2/
Time is precious. Waste it wisely.
Deleted User 101379
Profile Blog Joined August 2010
4849 Posts
January 24 2016 16:20 GMT
#14051
On January 24 2016 20:07 Manit0u wrote:
Well, you can do fast web apps in PHP frameworks like Symfony:
http://labs.octivi.com/handling-1-billion-requests-a-week-with-symfony2/


What that is essentially saying is: Cache everything with Varnish and then the poor performance of Symphony doesn't matter anymore, because you are only serving stuff from cache. Oh, and you must not use the slow parts of Symphony like ORM and your application must be a REST service and not actually serve any templated content.

I have no doubt that you can tweak every framework until you eventually have something fast, but for some frameworks the performance tuning takes up much more time than using the framework would have saved in the first place.

PHP as a language itself is not as bad as it used to be and performance wise it's fine, just some of the major frameworks are terrible.
Manit0u
Profile Blog Joined August 2004
Poland17389 Posts
Last Edited: 2016-01-25 00:28:42
January 25 2016 00:26 GMT
#14052
True enough. But even without all this caching and with very little optimization (and still using ORM and templating) we can easily get to 500ms response times in our apps. That's sufficient most of the time. 30ms is great for REST stuff but with actual views it's nigh-unachievable due to rendering times and amount of data you have to send.
Time is precious. Waste it wisely.
BByte
Profile Joined August 2011
Finland49 Posts
Last Edited: 2016-01-25 21:59:22
January 25 2016 21:58 GMT
#14053
The Octivi article may be an extreme example, but it's certainly possible to get decent performance with Symfony. We get response times of roughly 80 ms on simple pages, but that still includes several DB queries and Twig templates -- not that the latter really matters, templates get cached to PHP code anyway. That's on PHP 5.6 and even if PHP 7 isn't 100 % faster, it's still going to make a noticeable difference.

This has required no particular optimizations, in fact our service count sometimes terrifies me. But opcode cache is essential for any PHP application and Doctrine metadata cache is pretty much required as well. The latter should probably be expressed more clearly in Symfony docs as well, even if the cache can't be enabled by default because it requires an external caching solution.

More than 95 % of the time any performance problems relate the database anyway, and at that point the language and the framework only matter if they get in your way too much. For example using references with Doctrine is likely a micro optimization. Fetching a single record using the primary key typically isn't the performance problem. Of course doing it inside a loop can be an issue and sometimes references may be the right tool for the job. Same goes for the extra lazy collections -- sometimes useful, rarely needed. Overall query count is naturally important, and Doctrine can both help and hinder here. Sometimes collections and nested structures can make it hard to see why there are for example multiple queries. On the other hand, debugging is usually easy.

I'm not a huge fan of Doctrine overall and some Symfony components (Form and PropertyAccess come to mind) have problems as well. While the modern PHP frameworks were probably mainly influenced by Rails, at least Symfony certainly has Java roots as well. That means it's certainly not for everyone. But I haven't seen the ZF2 problems like bad exception tracking.

Overall I like writing JavaScript (ES6) a lot. For small projects it's great and for larger projects Flow or TypeScript can help. The ecosystem seems like a mess though. Not locking vendor libraries to a specific version (by default) is a bother and the tool stacks have so many dependencies it's no wonder that minor semver violations cause huge compatibility problems.

(And if a framework were to do only one thing, it wouldn't be a framework, it would be a library.)
Manit0u
Profile Blog Joined August 2004
Poland17389 Posts
January 26 2016 15:27 GMT
#14054
https://github.com/nvbn/thefuck

[image loading]

Brilliant!
Time is precious. Waste it wisely.
solidbebe
Profile Blog Joined November 2010
Netherlands4921 Posts
Last Edited: 2016-01-26 16:43:07
January 26 2016 16:42 GMT
#14055
Beautiful
That's the 2nd time in a week I've seen someone sig a quote from this GD and I have never witnessed a sig quote happen in my TL history ever before. -Najda
Thaniri
Profile Blog Joined March 2011
1264 Posts
January 27 2016 07:31 GMT
#14056
You guys have been really helpful in this thread, I'm reading some cool stuff about web development that is way over my head. Here's me trying to learn some javscript, trying to make a queue, of course it's not working out for me:

function queue(arr, item) {

testArr.shift(arr);
testArr.push(item);
return item; // just to see if anything works

}
queue([], 1); //doesn't work even if [] is replaced with a number.

var testArr = [1,2,3,4,5];


I'm trying to remove the front item of the array, then add the second number when the queue(); function is called.

I'm getting a TypeError: Cannot read property 'shift' undefined.

It works fine if I substitute in some numbers for the arguments I'm trying to pass.
Nesserev
Profile Blog Joined January 2011
Belgium2760 Posts
Last Edited: 2016-01-27 08:00:37
January 27 2016 07:57 GMT
#14057
--- Nuked ---
Thaniri
Profile Blog Joined March 2011
1264 Posts
January 27 2016 16:36 GMT
#14058
Hmm ok. Ill read that chapter and come back if I need more help.

It works fine if I simply remove the arguments of the method and just substitute in numbers, so the problem must be wrongheaded thinking on the shift and push.

Thanks.
Cyx.
Profile Joined November 2010
Canada806 Posts
January 28 2016 01:14 GMT
#14059
ugh... moved to vs2015 at work last week, and it takes siginificantly more memory to link... and since we statically link LIKE FUCKING EVERYTHING in this place linking some of our exes takes over 15 minutes now, consuming 5.5GB of memory in the process. Oh well, at least it gets people talking about using DLLs for some of our shit...
Shield
Profile Blog Joined August 2009
Bulgaria4824 Posts
January 28 2016 01:22 GMT
#14060
On January 28 2016 10:14 Cyx. wrote:
ugh... moved to vs2015 at work last week, and it takes siginificantly more memory to link... and since we statically link LIKE FUCKING EVERYTHING in this place linking some of our exes takes over 15 minutes now, consuming 5.5GB of memory in the process. Oh well, at least it gets people talking about using DLLs for some of our shit...


Is it Visual Studio really? What more is it doing then?
Prev 1 701 702 703 704 705 1032 Next
Please log in or register to reply.
Live Events Refresh
Next event in 20m
[ Submit Event ]
Live Streams
Refresh
StarCraft 2
OGKoka 205
SortOf 168
mcanning 63
StarCraft: Brood War
hero 1802
Flash 732
firebathero 417
GuemChi 359
Killer 339
Leta 259
Mini 188
Hyun 182
PianO 142
Soma 126
[ Show more ]
ZerO 107
ToSsGirL 76
Aegong 29
Free 25
Sacsri 15
Sharp 15
Rush 7
Bale 5
Mong 1
Dota 2
XaKoH 401
XcaliburYe169
canceldota73
League of Legends
JimRising 578
Counter-Strike
olofmeister1468
shoxiejesuss770
Stewie2K299
Other Games
summit1g7647
singsing798
ceh9571
B2W.Neo380
Hui .150
Mew2King56
Trikslyr13
ZerO(Twitch)6
Organizations
Other Games
gamesdonequick612
Counter-Strike
PGL270
StarCraft 2
Blizzard YouTube
StarCraft: Brood War
BSLTrovo
sctven
[ Show 15 non-featured ]
StarCraft 2
• LUISG 30
• AfreecaTV YouTube
• intothetv
• Kozan
• IndyKCrew
• LaughNgamezSOOP
• Migwel
• sooper7s
StarCraft: Brood War
• BSLYoutube
• iopq 0
• STPLYoutube
• ZZZeroYoutube
Dota 2
• WagamamaTV507
League of Legends
• Jankos1812
• Lourlo755
Upcoming Events
Replay Cast
20m
OSC
6h 20m
Tenacious Turtle Tussle
13h 20m
The PondCast
1d
OSC
1d 2h
WardiTV Invitational
2 days
Online Event
2 days
RSL Revival
2 days
RSL Revival
3 days
WardiTV Invitational
3 days
[ Show More ]
Afreeca Starleague
3 days
Snow vs Soma
Sparkling Tuna Cup
4 days
WardiTV Invitational
4 days
CrankTV Team League
4 days
RSL Revival
4 days
Wardi Open
5 days
CrankTV Team League
5 days
Replay Cast
6 days
WardiTV Invitational
6 days
CrankTV Team League
6 days
Liquipedia Results

Completed

Acropolis #4 - TS2
WardiTV TLMC #15
HCC Europe

Ongoing

BSL 21 Points
ASL Season 20
CSL 2025 AUTUMN (S18)
C-Race Season 1
IPSL Winter 2025-26
EC S1
Thunderpick World Champ.
CS Asia Championships 2025
ESL Pro League S22
StarSeries Fall 2025
FISSURE Playground #2
BLAST Open Fall 2025
BLAST Open Fall Qual
Esports World Cup 2025
BLAST Bounty Fall 2025
BLAST Bounty Fall Qual

Upcoming

SC4ALL: Brood War
BSL Season 21
BSL 21 Team A
BSL 21 Non-Korean Championship
RSL Offline Finals
RSL Revival: Season 3
Stellar Fest
SC4ALL: StarCraft II
CranK Gathers Season 2: SC II Pro Teams
eXTREMESLAND 2025
ESL Impact League Season 8
SL Budapest Major 2025
BLAST Rivals Fall 2025
IEM Chengdu 2025
PGL Masters Bucharest 2025
TLPD

1. ByuN
2. TY
3. Dark
4. Solar
5. Stats
6. Nerchio
7. sOs
8. soO
9. INnoVation
10. Elazer
1. Rain
2. Flash
3. EffOrt
4. Last
5. Bisu
6. Soulkey
7. Mini
8. Sharp
Sidebar Settings...

Advertising | Privacy Policy | Terms Of Use | Contact Us

Original banner artwork: Jim Warren
The contents of this webpage are copyright © 2025 TLnet. All Rights Reserved.